Is object.isVisible =false == object.alpha =0 ? And Some Memory Questions

Hi all,

I’m currently developing a simple game with Corona. I have a simple UI with 5-7 pages. When user starts to play the game ui is just fading out. When fading completes, ui’s isVisible property changes to false.

My questions about this method:

  • Do we really need to remove objects to free the memory? Or is it just enough to change isVisible property to false?
  • In Flash alpha=0 and visible=false are different. In Corona are they same? If not, what is the difference?

My last most important question:

  • What are the most effective ways to free the memory?

I think the answers to these questions will be a guide to all of us. I’m waiting your ideas, thoughts and experiences.

Thanks! [import]uid: 5629 topic_id: 1178 reply_id: 301178[/import]

  1. Yes, you need to remove all references to an object before it will be freed. Setting isVisible to false is a quick way to hide something without messing with it’s alpha value. Otherwise you, in a lot of cases, would need to remember the previous alpha value when you made the object visible again.

  2. You have to remove the object from any groups, tables, or variables. You do this via the remove method on some items and any variables you set to nil. The freeing of said memory happens automatically with garbage collection. If you have a highly FPS sensitive app, you can spread out garbage collection so you don’t get hit with a large dump at once.

Scott [import]uid: 5659 topic_id: 1178 reply_id: 3155[/import]

Thanks Scott,

Actually game is really simple. But I want to make it perfect. I don’t want memory leak or low fps.

Here is my other question. I use “ui.lua” file to create buttons in my ui. I’m now removing them. But what about their eventlisteners? Do I need to remove them also? Does garbage collection remove eventlistener, when its target is removed?

Thanks [import]uid: 5629 topic_id: 1178 reply_id: 3156[/import]

The GC is part of LUA. The event listener is something that is running inside the ObjC part of the Corona engine. You have to first remove that yourself. [import]uid: 5712 topic_id: 1178 reply_id: 3159[/import]

Thanks Mike!

Is there a easy way to remove it? For example:
object:removeEvents()

Or is there a way to get eventlisteners of their targets? For example:
object.events

If there isn’t any easy way, I need to update the ui file I think. [import]uid: 5629 topic_id: 1178 reply_id: 3161[/import]