Multiple Stages and resource destruction facilities

Come on erpz … your original request is available using groups…

Your understanding of object allocation and references is all but complete… In fact you still incist on being able to nil a table or object. :slight_smile:

You start to tell me stuff about weak tables and fail to include the most important information: Metatables … And in addition your example is useless.

Now you tell me about “getting” it … When I write about the allocation of images and tell me that I (
You know what? I bet you can not even give one example on where and why to use “nil” for a real world example. And just to say what I did not in the past… Your “correction” to my example code actually is creating the same with less elegant coding and introduces some ugly code… Which needs a nil to not leak the last element after it is not in the stage anymore. Which is exactly what I explained in one of my first posts. And that this is not needed usually … If you write elegant code.

Let me cite you: “In fact, by removing all objects from stage, Corona stops running automatically - i.e. no object to process anymore.” … Still smile about that one :slight_smile:

I believe that you got this effect because you where writing some bad code and the system crashed on you without you noticing why that happens and now you tell people wrong things out of your own misunderstanding of what is goin on.

And the newest and maybe most unrelated topic you can bring up besides your grandma: Talk about the iPhone Simulator from Apple … as if that would be of any importance …

To top this you send me a link to apple documents to show that different devices have different implementations? Doh? Do you know the iPhone photo app? Mine has more than 1000 images and works on iPhone, iPod touch and iPad … It’s a miracle!

Till now I was slightly entertained … But now I feel anger and regret the time I spent in writing code and demonstrating stuff to you.

I even think to have found a bug which affects your work … Wrote example code … Created a bug report. More than everything you did to support your feature request.

I am out of this thread… Just NIL my efforts… Have fun coding… No biggies… Bye!

P.S.: for the readers which missed why I am upset … Here his original post as I got it before he changed his mind and edited it:

"Fogview (and Oder to some extent),
who’s the dumb here when you run code for testing memory on the simulator
rather than on the actual device ?

OMG, you really *SHOULD* know that the Corona simulator AND the Apple iPhone
simulator DO NOT simulate memory restriction for the graphic processor.

This is the bad thing about forums: you end up teaching stuff to lil’kids
instead of getting serious stuff done or answered.

Get your homework done the next time you open your mouth:" [import]uid: 6928 topic_id: 1100 reply_id: 3343[/import]

Plain lua, no Corona…similar to your code:

[lua]s = {}

function run()
for i=1,1000 do
if i == 1 then
local t = {}

for j=1,10000 do – creates about 260 Kbytes worth of garbage
t[j] = math.random(1,1000)
end

s[1] = t

print(collectgarbage(“count”)) – prints ~ “281.5”
elseif i==2 then
table.remove(s) – t is removed from s
elseif i==1000 then
print(collectgarbage(“count”)) – prints ~ “277.7” … still not collected
end
end
end

run() – enters loop

collectgarbage()
print(collectgarbage(“count”)) – prints “21.6” … t is collected[/lua]
… when you can tell why, you can fix your code.

Oh, and you can close the bogus bug you filed to Ansca… it’s not their fault, the problem is just your code. It wouldn’t work in plain Lua either, as demonstrated.
[import]uid: 5750 topic_id: 1100 reply_id: 3344[/import]

No I promised myself to not respond … I won’t do it … But it is hard :slight_smile: [import]uid: 6928 topic_id: 1100 reply_id: 3345[/import]

@mike,
i’m sorry u see that way. Please check who started to call “dumb” who here.
I don’t usually reply to such things… I’m just sorry i did. [import]uid: 5750 topic_id: 1100 reply_id: 3350[/import]

Hi Erpy,

I guess you ment this


@erpy there is a nice saying about things you won’t say will not let you look dumb :wink:

I am sorry that I overlooked that. I guess you guys are even. What I didn’t like is the fact that you included Tom (fogview) with your comment. So it is you an Hans who call each other names. I recomment you guys go back to your projects. [import]uid: 5712 topic_id: 1100 reply_id: 3352[/import]

@Erpy: I think insulting people here says a lot about your character. Btw. everytime you edit a message, people who posted here will get a copy of that message. So it was interesting to see what you wrote. And makes me think twice if I should answer to your topics next time.

[import]uid: 5712 topic_id: 1100 reply_id: 3349[/import]

I just want to find solutions to problems. I did not expect that he gets started by that sentence. Which even has a wink smiley …

So please @erpy take my apologize … Never said you are dumb … [import]uid: 6928 topic_id: 1100 reply_id: 3357[/import]

Oder,
I’m glad for your excuses, and I owe you an apology myself for taking this way too far.
So, let’s try get back to “business”. :slight_smile:

I overlooked your code at first. Admittedly, nilling out that reference was useless.

The thing I found out programming in Lua in a runtime environment is that variables are collected in a very “lazy” way if the GC is not set properly, with “aggressive” parameters.

So, back to my previous code, which is based on yours but Lua-only, it’s sufficient to force a full GC cycle - although expensive in terms of performance:

[lua]s = {}

function run()
for i=1,1000 do
if i == 1 then
local t = {} – t is local

for j=1,10000 do – 260 Kbytes of Garbage
t[j] = math.random(1,1000)
end

s[1] = t – t is referenced in s

print(collectgarbage(“count”))

elseif i==2 then
table.remove(s) – removes t reference from s
collectgarbage() – forces collection
print(collectgarbage(“count”)) – at this point t has been already collected
end
end
end

run()

collectgarbage()
print(collectgarbage(“count”)) – this prints the same value as i == 1000[/lua]

A solution could be to set GC differently - which did not solved the problem in this case - or to call a collectgarbage(“step”,stepvalue) at each frame, which is an effective solution only if you find the right compromise between garbage collection and performance. (that’s a solution that worked for me in the past)

I got an explaination for this, and you guys are welcome at taking a shot at this:

Corona’s GC has probably a default thresholds based on available system RAM ( < 256 Mbytes), while garbage for images influences the video ram directly ( < 24 Mbytes in some cases). This leads GC to be too lazy, overflowing video RAM on the device before collecting anything.

[import]uid: 5750 topic_id: 1100 reply_id: 3359[/import]

@Mike,
I replied to Fogview in a harsh way, due to the overall thread “level”, although I hope I did not offended him in any way.

I edited my post simply because I confused who said what at some point… so what remains said to Fogview (my last edit) was never meant to be offensive to him. (although admittedly harsh)

What remains is that, unfortunately, graphics memory tests cannot be performed on the Simulator, either Ansca’s or Apple’s. [import]uid: 5750 topic_id: 1100 reply_id: 3360[/import]

I am sure the problem has nothing to do with the Lua Garbage Collector itself.

That is if you remove the references correctly there is no problem with that.

An image stays preloaded into memory even if you remove every Lua reference to it. We do not know “how long” and we seem to have no way to “flush” this cache in any way manually! It looks to me as if they purge the cache on device low memory warnings… and this seem to fail sometimes.

Those images do not (
Simple code to proof all of this at once:

for i=1,100 do  
 local t=system.getTimer()  
 collectgarbage('collect')  
 print(collectgarbage('count'))  
 local img=display.newImage("test.jpg")  
 img.parent:remove(img)  
 -- img=nil -- not needed because img is local anyway  
 print(i..": "..(system.getTimer()-t))  
end  

Output for the first few loops:

51.001953125 1: 133 51.025390625 2: 0 51.025390625 3: 0 51.025390625 ...  
(stays like this mostly ... for hours!)  

I hope this will stop this guesstimating and also hope Anscar looks at the bug report.

I believe that there is something seriously wrong but this seems to influence the iPhone only in my tests. [import]uid: 6928 topic_id: 1100 reply_id: 3361[/import]

I will try to write some repro cases as well.
I’ve already been told by Ansca about their caching mechanism when repeteadly loading an image with the same file name.
Thus I’d expect Corona not to free its own texture cache while the code above is running.

So, I’d personally stick more with the code you’ve written in the bug report, which loads different textures.

Anyway, I’ll probably be able to tell more in the next few days. [import]uid: 5750 topic_id: 1100 reply_id: 3366[/import]

@erpy

My comments about running the code in the Simulator was only to determine how Lua performed GC when an object was NIL’d and when it wasn’t. I was not running any graphics memory tests in the simulator.

Tom [import]uid: 6119 topic_id: 1100 reply_id: 3379[/import]