2 questions

BlitzMax Forums/BlitzMax Beginners Area/2 questions

Josepho(Posted 2007) [#1]
Im working on a project that has lots of images and i would like to know if its a good idea to re-use some of the global TImages that im using, the project has more than 200 global TImages at the moment and keep growing. I set them to null when i didnt use them, i would save more memory if i use them for show more than one image?

And the other question is, whats the use of "delete"? Its the same as putting the variable to null?


Gabriel(Posted 2007) [#2]
1. I'm not sure what you mean. You only need one copy of each image. If you have 10 identical images on the screen, just draw the same image 10 times. I don't think you'll save memory, because Blitz should be intelligent enough not to reload the image, but it's good practice to only load one copy of each image, just the same. If this isn't what you mean, I'm sorry, but that's the only possibility I could see from what you described.

2. No, delete is a Method all objects have. This method can be implemented for any and all of your custom types. It is not called until the garbage collector collects your object ( which in turn only happens when the object has no more references left. ) The delete methods are not guaranteed to be called within the scope of your program. ( The program may finish with some objects already ripe for collection but the garbage collector may not have collected them. At this time they will be collected as the program shuts down, so you won't leak resources, but the delete method may not be called before the program exits. )


Josepho(Posted 2007) [#3]
Thanks for the second answer

I will try to explain better what i want to say with the first point

I have 100 diferent pngs on my game resources, in my game only appears 50 of this pngs at the same time, should i re-use the global TImages variables that i use to show them for loading two of this pngs?

Whats the size of a null TIMage? Can i have lots of the without use them and not worry about the memory?


Gabriel(Posted 2007) [#4]
Ok, thanks for the clarification. No, you don't need to reuse your image variables. There's no cost to a null timage, because as soon as the garbage collector gets it, it's gone. All you've got is a variable. So probably a few bytes max. Use as many image handles as you need.


MGE(Posted 2007) [#5]
Thanks Gabriel for an informed answer, helped me as well! :)


Grey Alien(Posted 2007) [#6]
yeah image handles are negligable, same as sound handles and any Types that you pretty much, unless you are doing something weird.

but the delete method may not be called before the program exits


Cripes never knew that. So a final call to GCCollect() could be in order? Mind you I never use delete so it's no big deal.


Dreamora(Posted 2007) [#7]
No not even the final GCCollect() will guarantee that.

There is no guaranteed instant "drop resource" behavior in any managed language.
If you need something to happen, call a method and don't rely on the management.


Josepho(Posted 2007) [#8]
Thanks gabriel for the answers, you help me a lot ^_^