Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Memory Leak Issue
Started by crssmn Nov 24 2010 11:35 AM

- - - - -
35 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

erpy

[GLOBAL: userInfoPane.html]
erpy
  • Contributor

  • 154 posts
  • Corona SDK

As shown by jmp909, the object remains referenced by the eventListener system.
Try removing the object as a listener before calling removeSelf(), and print_r again.
uid: 5750 topic_id: 3987 reply_id: 12346


[TOPIC: post.html]
#27

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

Also I wonder isn't the 'local ball' still referencing the object hence the leak.
uid: 9371 topic_id: 3987 reply_id: 12348


[TOPIC: post.html]
#28

erpy

[GLOBAL: userInfoPane.html]
erpy
  • Contributor

  • 154 posts
  • Corona SDK

Nope, if all references are gone, that "local" is actually the keyword that allows for that variable within that scope to be then collected.
Once you "detach" the imageBall table from the listener and removeSelf(), it should be free to go, there.

Once references are gone, Lua GC will mark the local imageBall variable, in the scope it was created, as trash, and will eventually collect it.
uid: 5750 topic_id: 3987 reply_id: 12350


[TOPIC: post.html]
#29

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

Out of interest how do you detach the ball from the listener in this example?
uid: 9371 topic_id: 3987 reply_id: 12351


[TOPIC: post.html]
#30

erpy

[GLOBAL: userInfoPane.html]
erpy
  • Contributor

  • 154 posts
  • Corona SDK

Example of scope in Lua:

-- global scopedo -- first local scope	local var1 = "Within first local scope"	do -- second local scope		local var2 = "Out of scope"		do -- third local scope			local var3 = "Out of scope"		end	end	print(var1,var2,var3)endprint(var1,var2,var3)


Check out what it prints.
uid: 5750 topic_id: 3987 reply_id: 12352


[TOPIC: post.html]
#31

erpy

[GLOBAL: userInfoPane.html]
erpy
  • Contributor

  • 154 posts
  • Corona SDK

Out of interest how do you detach the ball from the listener in this example?

That's pretty straightforward. The obj is the imageBall object which was registered as a table listener by itself. Thus:

...if ( obj.y > 315) then                             	obj:removeEventListener("collision",obj) -- 
uid: 5750 topic_id: 3987 reply_id: 12353


[TOPIC: post.html]
#32

dweezil

[GLOBAL: userInfoPane.html]
dweezil
  • Contributor

  • 568 posts
  • Corona SDK

I meant in jmp's example - post number 21
uid: 9371 topic_id: 3987 reply_id: 12354


[TOPIC: post.html]
#33

erpy

[GLOBAL: userInfoPane.html]
erpy
  • Contributor

  • 154 posts
  • Corona SDK

Oh, in that example I'd nil out the object after removeSelf(). There is no object registered as an eventListener.
If that doesn't solve it, I'd check where the physics is added in the ball table and would apply a removeSelf() method to that object as well.
I haven't used Game Edition, but let's say if physics.addBody(ball) adds a ball.physics table, then I'd try:

if obj.physics.removeSelf then obj.physics.removeSelf() end -- just to make sure... if you know it's got the method, no use for the IF statement!


But I don't know if this is actually working that way in Game Edition, nor if the table is called that way... but Ansca says physics objects inherit the removeSelf() method. The point is...where's the physics object! ;)
uid: 5750 topic_id: 3987 reply_id: 12355


[TOPIC: post.html]
#34

jmp909

[GLOBAL: userInfoPane.html]
jmp909
  • Corona Geek

  • 1,328 posts
  • Corona SDK

there's no such thing as obj.physics

when you nil out the object and print_r(obj) you get nil. but there's apparently still a memory leak internally. my guess is something in the physics engine is still holding on to a reference. that's not something we have control of.
uid: 6645 topic_id: 3987 reply_id: 12391


[TOPIC: post.html]
#35

jonbeebe

[GLOBAL: userInfoPane.html]
jonbeebe
  • Contributor

  • 511 posts
  • Corona SDK

I would forward this issue (as well as a link to this thread) to bugs@anscamobile.com and see if they can confirm a memory leak, and if so, at least it'll be on their "todo" list of things to take care of for the next release.

If it is a memory leak, great catch!
uid: 7849 topic_id: 3987 reply_id: 12568


[TOPIC: post.html]
#36

crssmn

[GLOBAL: userInfoPane.html]
crssmn
  • Contributor

  • 285 posts
  • Corona SDK

I've been working on a work around for this issue, but came across another leak issue. Any thoughts would be helpful. Link: http://developer.anscamobile.com/forum/2010/12/30/memory-leak-touch-listener
uid: 10903 topic_id: 3987 reply_id: 15281



[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]