Memory leaks with objects
BlitzMax Forums/BlitzMax Beginners Area/Memory leaks with objects
| ||
In writing a custom list type for improved performance I am constantly finding memory leaks. Could someone please explain why the following test program shows a memory change of 12 bytes?Framework BRL.Basic Type MyObject Field o:MyObject End Type Local o:MyObject Local mem:Int GCCollect() mem=GCMemAlloced() o = New MyObject 'Create an object o.o = New MyObject 'Create another object o.o = Null 'Now the second object should be deleted at GCCollect() o = Null 'And the first one GCCollect() mem = GCMemAlloced() - mem Print mem Am I missing something obvious? |
| ||
4 0 0 0 0 0 0 0 With repeat forever So...... I would imagine (And this is a guess), that the first time you ask for an Object, somesort of stucture template is created. Honestly, its not a memory leak unless it goes up and up every cycle. BUt Im still gonna check back when those clever people comment ;) |
| ||
put all the o stuff inside a function. When you declare as local in the main program it doesn't get freed when you set it to null even though you expect it to be. I went through the same thing recently. |
| ||
The objects are still "in scope", so it's very likely that Max is hanging onto the memory (of the variables) incase you were to create a new instance of it. Trying the same trick from inside a function should result in a different answer. Not sure about a Local variable declared inside a loop in the main program though... |
| ||
Local variables in the main function just means they cannot be accessed by any function you declare, this can be good for multi declarations but can be a serious pain to debug at later stages. |
| ||
So that isn't the cause of my problem, since in the real code everything is done in functions. I have to delve deeper... |