how do I free stuff?
BlitzMax Forums/BlitzMax Programming/how do I free stuff?
| ||
how do I free images? is Flushmem only for Types? Is everything freed on the End command, just like in Blitz3d? |
| ||
As far as I understand, all you need to do is erase all references to a resource. For example:test_image = LoadImage("test.jpg") DrawImage test_image, 0, 0 test_image = NULL Flushmem In the above, setting the test_image to none, and then flushing the memory, would erase your image test_image. |
| ||
You can also use the Release command:Release test_image Flushmem And everything is released at the end of the program, as usual. |
| ||
ok thanks I made this Print MemAlloced()+" beginning" Graphics 800,600 Print MemAlloced()+" after graphics" i=CreateImage(400,400) Print MemAlloced()+" after createimage" 'i=Null Release i Print MemAlloced()+" after release image" flushmem Print MemAlloced()+" after flushmem" EndGraphics Print MemAlloced()+" after endgraphics" end eraseing all refrences to the image and flushmem does not free it. you have to use the Release command |
| ||
eraseing all refrences to the image and flushmem does not free it. That's because you aren't using references. you have to use the Release command Well that, or you have to use objects.Print MemAlloced()+" beginning" Graphics 800,600 Print MemAlloced()+" after graphics" Local i:TImage=CreateImage(400,400) Print MemAlloced()+" after createimage" i=Null 'Release i Print MemAlloced()+" after release image" flushmem Print MemAlloced()+" after flushmem" EndGraphics Print MemAlloced()+" after endgraphics" endRead this thread for more information on how the "Garbage Collector" works. |
| ||
Yes, I made a mistake in my test code. This would work:Local test_image:TImage = LoadImage("test.jpg") DrawImage test_image, 0, 0 test_image = NULL Flushmem The way I had it before, test_image was just an integer making a reference to the real test_image object. But when declared as a TImage, you are accessing it directly. Sorry about the confusion! |