Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Help with a small leak (TNT Particle) — Gideros Forum

Help with a small leak (TNT Particle)

gianmichelegianmichele Member
edited November 2012 in General questions
Hi everyone,

I'm trying to get a small particle effect into my game, thanks to the incredible TNT Particle. It works great if not for a very small leak that I can't squash.

Here's the class
ParticleFx =gideros.class(Sprite)																		
 
----------------
-- CLASS INIT --
----------------
 
function ParticleFx:init(t, posX, posY, layer)	
 
	self.particle 		= CParticles.new(t, 30, 0.5, 0.3, "alpha")
 
	self.particle:setSpeed(350, 450)												
	self.particle:setDirection(-180, 180)
	self.particle:setColor(0,0,0, 255,255,255)										
	self.particle:setAlpha(0)													
	self.particle:setSizeMorphIn(5, 1.5, 2)	
	self.particle:setGravityForce(0,0)
	self.particle:setGravity(0,0)
	self.particle:setAlphaMorphIn(255, 0.2)
	self.particle:setAlphaMorphOut(0, 0.8)
	self.particle:setLoopMode(1)
 
	self.emitter 		= CEmitter.new(WIDTH/2, HEIGHT/2, 0, layer)
	self.emitter:assignParticles(self.particle)
	layer:addChild(self.emitter)
 
	self.emitter:addEventListener("EMITTER_FINISHED", self.onEmitterStop, self)
	self.emitter:start()
 
end
 
function ParticleFx:onEmitterStop(event)
 
	self.emitter:removeEventListener("EMITTER_FINISHED", self.onEmitterStop, self)
	self.emitter:free()
	self.emitter	= nil
	self.particle 	= nil
 
end
When I instantiate the class from my game loop, every time it leaves something in memory when finished (I'm counting memory with a snippet found here). Something small, like 1 to 3 units. But that adds every time.

If I take the code out of the class and create the explosion directly in the game loop (but I don't destroy and recreate it every time), this has no leaks.

Any suggestion?

Thanks,
Gian



Dislikes: zer0flag

Tagged:
+1 -1 (+0 / -1 )Share on Facebook

Comments

  • Should you maybe remove the emitter from layer. In your init function, you add self.emitter as a child of layer
    	layer:addChild(self.emitter)
    maybe removing it using
    	self.emitter:getParent():removeChild(self.emitter)
    might fix your problem. No guarantee but it might :D

    Likes: anefiox

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks tried it. It's a bit better but still there's a small leak (grrrrrr)
  • MellsMells Guru
    edited November 2012
    Not really to bring a solution, just to add that :
        self.emitter:getParent():removeChild(self.emitter)
    can also be replaced by :
        self.emitter:removeFromParent()
    cc @Scouser

    @gianmichele
    Did you try to collect garbage manually after niling your emitter on EmitterStop?
    collectgarbage()
    collectgarbage()
    collectgarbage()
    collectgarbage()
    Just throwing ideas.

    And maybe @GregBUG has an idea?
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • Yep, tried all of that as well...
  • GregBUGGregBUG Guru
    edited November 2012
    mmm... i checked tnt particle and it seemes to me that i release all when you call free() method.

    maybe releated with internal lua garbage collector ?

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • GregBUGGregBUG Guru
    edited November 2012
    it seems that if you use an object inside another object memory leak occur...

    i try to explain...

    for example ...
    tntMotion = Core.class()
    with some methods...

    tested... allocated
    called some methods and then
    called free() methods e no memory leak at all.

    ok. it's fine.

    but if i use this class (tntMotion) inside another class:
    -- Define enemy class -----------------------------------
    local enemy = Core.class(Sprite)
    function enemy:init(sGFX)
    	self.spriteGFX = sGFX
    	self.motion = tntMotion.new()
    end
    function enemy:free()
    	self.spriteGFX = nil
    	self.motion = self.motion:free()
    	collectgarbage()
    	return nil 
    end
     
    local l = enemy.new(spriteGFX)
    l = l:free()
    memory leak occur (about 1k of memory)

    mmmm...
    what's wrong here... i can't see... :-?
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • Yep, same result. Could be a bug in Gideros?
  • no official answer from Gideros Stuff ?

    maybe i missing something important in Lua/Gideros coding at this point...

    :-O
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • it seems that if you use an object inside another object memory leak occur...

    i try to explain...

    for example ...
    tntMotion = Core.class()
    with some methods...

    tested... allocated
    called some methods and then
    called free() methods e no memory leak at all.

    ok. it's fine.

    but if i use this class (tntMotion) inside another class:
    -- Define enemy class -----------------------------------
    local enemy = Core.class(Sprite)
    function enemy:init(sGFX)
    	self.spriteGFX = sGFX
    	self.motion = tntMotion.new()
    end
    function enemy:free()
    	self.spriteGFX = nil
    	self.motion = self.motion:free()
    	collectgarbage()
    	return nil 
    end
     
    local l = enemy.new(spriteGFX)
    l = l:free()
    memory leak occur (about 1k of memory)

    mmmm...
    what's wrong here... i can't see... :-?
    Are you sure that motion:free() returns nil?
    Set also enemy=nil
    And you can also try setting the container class as weak once you want to delete it, in your example:
    enemy = setmetatable({}, {__mode = 'v'})
    collectgarbage()
  • GregBUGGregBUG Guru
    edited November 2012
    @Javi

    yes i'm sure motion:free() returns nil
    and i tried to set manually enemy=nil
    but not differences... :(

    not tried

    enemy = setmetatable({}, {__mode = 'v'})
    collectgarbage()

    as soon as i go home i'll try.
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • @Atilim: I can probably work around this, but I prefer to solve it properly. Any help?
  • GregBUGGregBUG Guru
    edited November 2012
    sad and worrying to note that @Atilim no longer responds ... a time was not so ...

    probably these are "stupid" problems that only me and @gianmichele notice ...

    okay. better to move on ...
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • ar2rsawseenar2rsawseen Maintainer
    edited November 2012
    @atilim probably has his own reasons to spend less time on forum and more on development. It's in our own interests, isn't it? :)

    Or he just probably got fed up of squeking about new platforms as desktop or Windows 8 and decided to pull up couple of all nighters to make that happen :D
  • ...so hope it will be then...
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • @ar2rsawseen i agree but some blog update will be nice!
    this will help to spread gideros sdk!!

    if can can remember correcly last email newsletter from gideros is from last christmas right?

    hey but where is @gorkem ? :P

    Likes: gorkem

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.