Game Development Community

Safe Delete Query

by Scott Wilson-Billing · in iTorque 2D · 03/30/2010 (3:31 pm) · 5 replies

I have been using safeDelete on my scene objects and am now looking at lowering the memory footprint of the app.

I've noticed that if I call isObject(%this.obj) after calling %this.obj.safeDelete() the object is still there. I realise from looking at the source code that the delete requests are batched and the object is deleted when safe to do so. My question is this ... if I reuse the handle, %this.obj shortly after the safeDelete, will I be negating the deletion of the object previously referenced by the handle and inadvertently cause a memory leak?

Cheers

#1
03/30/2010 (3:43 pm)
No, you will not be negating the request.
On the other hand you should do it either.
Optimally you would do the safeDelete and then replace the content of the variable with "no object" so you don't work on something thats deemed to not be around any longer as your code will otherwise basically be "random code"
#2
03/30/2010 (4:09 pm)
Thanks Marc. In the context of iWT I am using the variable as a reference to the current loaded skyline. So at the end of a level I run the level clear code and safe delete the current skyline. At the start of the next level I reuse the skyline variable to point to the next skyline image map, however I've noticed at this point the previous skyline object is "still around". I think this is okay?

Cheers
#3
03/30/2010 (4:19 pm)
Stupid question time ... do I have to remove an object from the scenegraph before calling safeDelete ?
#4
03/30/2010 (5:20 pm)
Normally removing it is not required.
But at the end of the level I likely wouldn't use safeDelete as I want it to be gone for sure, so I can be sure that the two images are not present at the same time
#5
03/31/2010 (2:22 am)
I'm thinking the same, so to be sure, I'll remove it from the scenegraph.
Cheers