Garbage Collection Checklist?

BlitzMax Forums/BlitzMax Beginners Area/Garbage Collection Checklist?

Gabriel(Posted 2005) [#1]
I'm trying to refactor someone else's code, including making it much more OO, and moving things around between types. It's going very nicely in all ways except one. Types are not being Delete()'d. I have a Destroy() method which removes the object from the global type list and also removes a reference from a container type. There should not be any more references anywhere except locals which go out of scope. I call FlushMem in the main loop only.

I'm just wondering if there's anything I could be checking to help me find why it's not being freed correctly. I remember seeing something about FlushMem having scope but there's nothing in the FlushMem documentation when I double F1 ( well there wouldn't be, would there? )

I doubt that's the problem, but I have to consider all possibilities now. For reference, yes, the destroy method is verified as being called, and yes, FlushMem is definitely being called every frame.


Dreamora(Posted 2005) [#2]
Flushmem only cleans the current and subscope. So if called from a function, it only frees stuff that was created during the running of this function, not what had existed before its execution.

Because of that, it is normally called in the mainloop as its commonly the "lowest" existing scope.


tonyg(Posted 2005) [#3]
When you say 'Global type list' you're not referring to anything similar to the B3D Global type list because, I;m sure you know, Bmax hasn't got one.
You are using listremove for each list that the type has been added to?
If this doesn't help try setting the type variable handle to null and see what happens. Mark suggested it's not necessary but you never know...
Memory management


Robert Cummings(Posted 2005) [#4]
Basically if you want to emulate Blitz3D's way of thinking and not worry about memory, just place it before your flip.

The scope is always the present and any routines called below it, therefore no worries if you stick it in your main loop.

It's only optional because you might want to create and free one million types and THEN flush the memory when you're ready. Overall, it gives Blitzmax a nice speed boost.

For most games, it's perfectly ok to stick it before the flip.


Gabriel(Posted 2005) [#5]
Thanks guys, it looks like it was just a case of FlushMem scope. Although I was calling it in the main loop, right after flip, the main loop is housed in a "master" type called game which controls everything else. I've made a new main loop which calls the old main loop and moved FlushMem from the old one to the new one and things are being deleted now.

Tony: Right. when I said global type list, I meant a type list stored in a global type variable. I remove all the entries from the list when destroying them.