GC is pretty damn thorough.

BlitzMax Forums/BlitzMax Programming/GC is pretty damn thorough.

Grey Alien(Posted 2007) [#1]
I've been testing GCCollect all day to 100% find out what I need to free up manually and the answer appears to be "nothing", except for circular references OR if I deliberately want to reduce memory usage halfway through my app.

check this out:



You need some media to run it (logo.png and testound.wav).

Basically the start and end memory consumption values are the same (in non-debug mode!). So I've made types containing sub-types, loaded images, sounds, created channels that I'm playing sounds on, made a list, populatated the list with types that include images, and it all frees up fine. Note I haven't even had to use List.Clear(). Haven't needed to manually Null the images, sound or channel. It all works, wow. OK that'll save me some time.

Anyway, one thing to watch out for is that notice how the sound carries on playing after b and a are nulled (use a long sample). Well that's because the channel still exists and has a pointer to the sound I guess. If you don't free the channel properly with StopChannel then you'll have a memory leak (from a task manager point of view). I found this out with an early version of the framework. Nulling a channel is not enough.

Channels are weird anyway because you can't do myChannel:TChannel = New TChannel, you have to use AllocChannel() so just remember to use StopChannel() to close it down properly.

Hope this helps some of you out there, and if anyone has anything to add please post!


Grey Alien(Posted 2007) [#2]
Oh, I didn't test arrays. Anyone?


JoshK(Posted 2007) [#3]
Well it should be thorough. It either works or it doesn't.

The problem I have with GC is that when you are designing a complex app, you are going to have circular references all over the place. So you end up having to manually free everything anyways, and you never really know if you are freeing everything or not, except that memory leaks will appear in a loop. At least with manual deletion you get a crash if you try to access an object that doesn't exist.