Object deletion

I am creating a game which generates objects at a regular interval, and I have found that after a while the game begins to lag. To delete a previous object to stop the game lagging do I do:

object:removeSelf()

or object = nil

and do I need to collectgarbage()

which of these do I need to use to delete an object and stop the game lagging? Also, is it possible to remove all of the objects in a table without having to individually remove them? [import]uid: 116264 topic_id: 24627 reply_id: 324627[/import]

Both:
object:removeSelf()
object = nil

I also find when I have fast action, the garbage does not get taken out fast enough so I have a Timer that calls a CollectGarbage() function every 20 seconds.

[import]uid: 21331 topic_id: 24627 reply_id: 99790[/import]

If you don’t have a variable reference to any object in a particular display group I believe that group:removeSelf() will remove them all but you should double check in the API docs as there used to be a bug there. That is a good starting point anyway. [import]uid: 8271 topic_id: 24627 reply_id: 99798[/import]

http://developer.anscamobile.com/reference/index/objectremoveself

you should set to nil. [import]uid: 21331 topic_id: 24627 reply_id: 99809[/import]

So i don’t ever need to collectgarbage() ? [import]uid: 116264 topic_id: 24627 reply_id: 99823[/import]

Most likely not. I just noticed pretty heavy mem-creep in some fast areas and found that collecting every once and awhile proved to me that I did not have a leak. Watch your mem, and see what you think. :slight_smile: [import]uid: 21331 topic_id: 24627 reply_id: 99826[/import]

What about display.remove(object) from what I am told that checks to see if nil before removing.

Ever since I found out about that, I’ve been using it ever since and don’t use removeSelf() anymore.

I am not collecting garbage (well for one it stanks, eww lol) and I haven’t found mem creeping up either when I change scenes.

Just started with it 2 weeks ago, so not sure if it is the cats meow or not.

ng [import]uid: 61600 topic_id: 24627 reply_id: 100374[/import]

different issue.
display.remove() may check for nil, this post wanted to be sure it was nill’ed. simply removing, by either method, is not enough. It will only remove the Corona display object, the table data that you attach to it will still exists. So you should set to nil.

I don’t use scenes yet. Made my own. When generating a lot of objects, and checking mem, I found it to creep. It would probably go down between “scene” changes, but my “scenes” were possibly long 2-player battles. I used the gc timer to keep things tidy.

two weeks, hugh… :slight_smile: [import]uid: 21331 topic_id: 24627 reply_id: 100432[/import]

Interesting. I’m using director (but without the module…see all, it’s a {} now)
When I switch scenes I am at 4.892 then it goes to 8.121 and when I switch back it’s still 4.892.

Maybe its the clean function or something, not sure but yea 2 weeks. I launch it everyday, but it hasn’t been running for 2 whole weeks lol, that would be nutty.

:slight_smile:
Now only if I could cure this wretched box2d tunneling issue…grrr.

ng [import]uid: 61600 topic_id: 24627 reply_id: 100456[/import]

oh no, I meant I know you have been programming this stuff for a while now, and I happen to know you’re nutty (in a good way!), so I thought you were making a joke…LOL! sorry for confusion.

Here is what I learned from:
http://developer.anscamobile.com/content/application-programming-guide-graphics-and-drawing#Removing_Objects_Properly

Maybe things have changed since I started…

and i can’t count the wasted days dealing with tunneling… [import]uid: 21331 topic_id: 24627 reply_id: 100465[/import]

Good points :slight_smile:
As far as the @#$@#%@#@!#%@! tunneling ya, it’s PISSING ME OFF to no end. I hate that I have to compromise my gameplay to bed to the will of this issue. I think from what my noob mind can understand is something to do with “math rounding”. I see in Cocos2d people do “time stepping” and some other stuff.

I’ve even “invented” what I call the “MLMOCD” or multi layer multi object collision detection. If you have a circle that is radius 30. Then I would have another circle embedded in that circle with a radius of 20. I would then put sensing logic that states something like if inner circle is within 8 pixels of a wall then apply linear damp of .30 or something like that.

So if the radius was 20 and the inner ball was 10, then I would take the space in between and minus a few pixels. That way, when the ball “absorbs” into the wall there would be some counteraction to it.

Oh wait theres more. Well, that only works so well in my play mechanic ALL objects are dynamic, and I have 100’s of pivot welds etc. MLMOCD works well on other games I’m working on but I wrote it for this current project and well, it’s not doing that hot :confused: haha. I thought cocos2d would be better, it wasn’t. I built out in Unity3d pro as well, performance was crappy though since I was forcing a 2d field in a 3d world. …grrrrrrrrrr.
Back on topic, I went ahead and nilled out all references (just in case) hahah. [import]uid: 61600 topic_id: 24627 reply_id: 100491[/import]