YAL question

Okay, it's Yet Another Leak question.

I tried to use from the 'share code', the great lightnings effects.
Thx to the really cool Corona Profiler lib, I know that the following code causes a great leak.

I have tried to narrow the issue to a single function. Any help would be welcomed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
        local function doLightnings()
 
                -- gundersen code inserted in a Layer :
                lines = display.newGroup()
                effectLayer:insert(lines)               
 
                local function drawLightning(x1, y1, x2, y2, displace, r, g, b)
 
                if displace < 1 then
                --glow around lightning
                                for i = 1, 2 do
                                        local line = display.newLine(x1, y1, x2, y2)
                                        line:setColor(r, g, b)
                                        line.width = 20 / i
                                        line.alpha = 0.05 * i
                                        lines:insert(line)
                                end
                --bolt itself
                                local line = display.newLine(x1, y1, x2, y2)
                                line:setColor(r, g, b)
                                lines:insert(line)
                        else
                                local midx = (x2+x1)*0.5
                                local midy = (y2+y1)*0.5
                                midx = midx + (mRandom(0, 1) - 0.5)*displace
                                midy = midy + (mRandom(0, 1) - 0.5)*displace
                                drawLightning(x1, y1, midx, midy, displace*0.5, r, g, b)
                                drawLightning(x2, y2, midx, midy, displace*0.5, r, g, b)
                        end
                end
 
                local function timerDraw(e)
                        timer.cancel( e.source)
                        drawLightning( 0, 0, _W, _H,100, 255, 100, 100)
 
                        local function timerClear(e)
                                timer.cancel( e.source )
                                display.remove(lines);
                                lines = nil
 
                                lines = display.newGroup();
                                effectLayer:insert(lines);
                        end
 
                        timerStash.newTimer = timer.performWithDelay(mRandom(300), timerClear, 1)
                        timerStash.newTimer = timer.performWithDelay(mRandom(3000), timerDraw, 1)
 
                end
 
        -- tmr launch
                timerStash.newTimer = timer.performWithDelay(mRandom(2000)+1000, timerDraw, 1)
 
        end

Antheor,
Here is a profiler result for this snippet of code:
http://www.mydevelopersgames.com/site/Profiler/LightningTest/profileTimeline.html

Did you profile long enough to enter the timerClear function? If not then you will probably see a huge numbers of allocation events (due to the new lines) with no matching deallocation events. But appearing from the graph there are no memory leaks, all the troughs of the sawtooth shape go to the same memory.

Thanks,
M.Y. Developers

Oh, this is a good news.
Sorry I misunderstood Profiler warning "change in memory is 92k".
I noticed the sawtooth shape, but I had noticed that it was not going back as low as it should have. I was wrong.

Thx for your support.

views:1800 update:2012/1/3 13:02:13
corona forums © 2003-2011