Array of images and memory changes

BlitzMax Forums/BlitzMax Beginners Area/Array of images and memory changes

Bremer(Posted 2007) [#1]
I have a question regarding array of images. In the following code, I load a number of images from a folder into an array. But if I reload them, I was expecting to have the program use the same amount of memory as before, at least about the same after a while and the memory cleanup had occured.

But while its the same images loaded each time, the program uses everything from around 90mb to 400bm, which doesn't seem ideal, and I would like to have it use about the same with each reload of the images.



It likely that there is something I am missing about using array to store images, and how the memory clean up works. And if so, it would be nice, if someone could point me in the right direction of how its done properly.


ImaginaryHuman(Posted 2007) [#2]
Where do you set your loaded images to Null to remove them, and where is your GCCollect?


Azathoth(Posted 2007) [#3]
If you're overwriting the references there is no need for Null, and unless you've set the gc to manual you don't need to explicitly call GCCollect.


Dreamora(Posted 2007) [#4]
1. I miss strict or superstrict. Without them, several scope optimations don't exist. Might cause some of the problems if not all of them.

2. You are right, you don't need to null.
But as you defined your array global it might be wise to do it. A global never goes out of scope and is handled differently than locals when it comes to automatic cleanup.

3. If both does not change anything, create a bug thread.
In that case I assume that the issue behind this one is similar to the issue behind "why images don't survive fullscreen -windowed" changes anymore


Azathoth(Posted 2007) [#5]
If hes calling loadPictures a second time the array will be overwritten with new references. Good chance the GC just hasn't cleaned up the old references yet, if he wants it to hurry up he should call GCCollect after the second loadPictures.


Dreamora(Posted 2007) [#6]
removed as beeing wrong (that happens when you start getting used editors instead of handwritting ...)


Azathoth(Posted 2007) [#7]
Here the keydown event is only getting sent once, however keyrepeat is getting sent if I hold down space. Keyhit doesn't seem to exist, there is a keyup instead.


Dreamora(Posted 2007) [#8]
Updated my post above.

But the problem might remain: On what time scale does it spike up that much? the GC won't do "every 10ms" cleanups and the like, which is the reason this kind of tests normally totally break as they don't test the GC in a real circumstance for which a GC is actually geared.


Bremer(Posted 2007) [#9]
It seems like Azathoth was right about the garmage collector not cleaning up fast enough. I added a GCCollect call right after re-loading the images and it brings the memory usage right down to the same each time.

I usually use superstrict, but left it out for this quick example. Adding it did not bring up any errors, so I think that the code is alright. I has just forgotten, that garbage collection could be called upon manually, but figured that the automated way was good enough.

Thanks for the help guys.