Gridview not deallocating on removing / memory leak

System: SDK 1.11.1, on M1 iMac, Nova, macOS 12.4

Expected: When creating a gridview, and then subsequently setting it to nil, it's expected that the memory is properly released (or, that there is a dedicated :remove function on ui.gridview?)

Repro: Run the below project, press A repeatedly to create and remove gridviews. Check malloc map to see consistent increases in heap usage.

Notes: I'm pretty green with memory allocation stuff, so I may not understand how Lua or the SDK is supposed to handle things when set to nil. If there's a proper way to "destroy" something like this and I'm not aware, please let me know !

gridview-test.zip (137.9 KB)

gridview-test

Update: As of the 1.12.0 update, this "leak" (or whatever was happening) is fixed! I couldn't find anything specific in the changelog that mentioned anything about changes to gridview, but I'm glad it's fixed. :slight_smile: Thank you devs !

1 Like

Hate to revive this from the dead, but it seems to have been reintroduced in either 1.12.1 or 1.12.2.

To repro, just download again the project above "gridview-test.zip" and run it in 1.12.2, and press A repeatedly. View the malloc map to see continual increase.

This is relevant (and I realized it again) because I'm using it in a project where I'm creating and destroying gridviews somewhat often.

Any ideas on what this could possibly be?

Hey, it seems I've run into this bug too!
From what I can tell timerX and timerY are not being removed.
I've added this to the removal of my gridview and it seems to have helped.

self.grid.timerX:remove()
self.grid.timerY:remove()
self.grid = nil

where self.grid is a reference to my grid view

2 Likes

This is interesting as it raises the question of what is actually removed. Let's say we have a class extending sprite but in which we had a timer and potentially other stuff.
Are the other variables/objects deallocated when we do mySprite:remove() or do we also need to do mySprite.myTimer:remove() (and would we need to set a table to nil for instance?)

I finally got a chance to look into this and it was indeed a problem related to the timers never being removed! I've got a fix ready now so hopefully we can get that released soon.

1 Like

was this ever fixed?? because I'm also currently having this issue. Im even removeing the timers and there is still a memory leak of about 2KB

Yes I believe the fix was included in the 2.0.3 release. Sounds like this could be a different leak - if you have some sample code that demonstrates the problem I'd be happy to check it out!

I was not updating timers. This was preventing them from getting garbage collected.