Releasing LoadImage memory under MAX 1.14

BlitzMax Forums/BlitzMax Beginners Area/Releasing LoadImage memory under MAX 1.14

Sin of Nature(Posted 2005) [#1]
Under BlitzMax 1.14, I had to add :TImage to the line to load an image. However, now my Release command no longer works. The error message is "Subexpression for release must be an integer variable"

	Local MyImage:TImage=LoadImage("MyPicture.bmp")
	Release MyImage


Now, I know that BlitzMax has its own memory cleanup no but how do I free up the memory correctly now (without BlitzMax own cleanup)?

Sin


Ferminho(Posted 2005) [#2]
When using release, you weren't freeing the image but the "pointer" to the TImage (that has to be freed using release, when you use an INT to reference an object like TImage. When you use a TImage there's no need to use release)

The image was freed up by BMax's Garbage Collector, and so will be now. When MyImage goes out of scope or is referencing Null or another image, MyPicture will be freed up.


Yan(Posted 2005) [#3]
In other words, don't try releasing objects and let BMax worry about managing resources. After all, that's the whole point of having automatic garbage collection.


Sin of Nature(Posted 2005) [#4]
Thanks. Thats what I thought, but wanted to make sure (as otherwise it would be a memory leak). Hmmm, not sure I like relaying on automatic memory handling though.

Cheers.

Sin


tonyg(Posted 2005) [#5]
You can always "Use GCSetMode to enable/disable automatic GC. To perform a manual GC, use GCCollect".
(taken from releasenotes.doc) or force a collect
using GCCollect.


Perturbatio(Posted 2005) [#6]
You can always "Use GCSetMode to enable/disable automatic GC. To perform a manual GC, use GCCollect".
(taken from releasenotes.doc) or force a collect
using GCCollect.


(after NULLing the object)


Dreamora(Posted 2005) [#7]
This doesn't change anything. You still don't free it manually. The GCCollect is just the command to force the garbage collector to collect unused ressources. Its still not freed but pooled for further usage.


tonyg(Posted 2005) [#8]
Its still not freed but pooled for further usage.


Hmmm.. Are we sure this happens?
If so, running GCMemalloced should only show increasing or stable mem usage unless you mean BlitzMax keeps the pool seperate to the application.
If *that* is true then I don't see how the .exe also shows lowering memusage.
You'll notice that it reports lower usage in this example gcmemalloced
as if memory *IS* being freed.
<edit> I reserve the right to have completely misunderstood.


Yan(Posted 2005) [#9]
If the GC just continued to horde memory, what would be the point of it's existence?

Also, does it still collect garbage when no one is around?


Ferminho(Posted 2005) [#10]
If I understand you correctly, in auto mode, it does

I won't continue to horde memory if you don't, because already allocated memory will be used next time you call your loadimage -or whatever-.

Tonyg, have you checked the app with an external memory usage monitor (like taskmgr in Windows 2K/XP)? just to be sure if it really frees memory or allocates it somewhere else or something.
(I'd do it but I'm at work now)


tonyg(Posted 2005) [#11]
Hmmm.. taskmanager reports a higher, stable figure.
I guess BlitzMax does have a 'memory currently in use' (gcmemalloced) and memory 'stored' for use (figure shown in taskmanager).