Re: [Flashcoders] Weak eventListener Problem
No, it's not true. You're misunderstanding how weak listeners work, how anonymous functions work (you shouldn't use those anyway), and you're also misunderstanding how the garbage collector works. Whenever you addEventListener, immediately write a function that removes the event listener (such as a destroy method). If you get into this habit, you will never forget to do it and you'll never have this issue ever again. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Weak eventListener Problem
I make destroy methods, avoid using extra references to listeners and am compulsive about cleaning them up, still some continue to execute imperviously. I hate when this happens cause its unpredictable and unexplainable. All I know is the Real garbage collectors are sometimes late picking up my garbage after I put it outside for them. -- Keith H -- www.keith-hair.net Steven Sacks wrote: No, it's not true. You're misunderstanding how weak listeners work, how anonymous functions work (you shouldn't use those anyway), and you're also misunderstanding how the garbage collector works. Whenever you addEventListener, immediately write a function that removes the event listener (such as a destroy method). If you get into this habit, you will never forget to do it and you'll never have this issue ever again. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Weak eventListener Problem
@Steven, I know anonymous functions are horrible, but I was trying to anything to get the GC to pick it up. I'm really just testing, to see how GC might react, and how the weak event listeners work. I know mediocre practice (and higher) you need to remove event listeners. I was just wondering, I've made a few classes that use weak references so that the person using my class does not have to worry about GC with the object. I wanted to make sure that it works how I thought it would. Ktu On Sun, Nov 8, 2009 at 10:59 AM, Keith H kh...@nc.rr.com wrote: I make destroy methods, avoid using extra references to listeners and am compulsive about cleaning them up, still some continue to execute imperviously. I hate when this happens cause its unpredictable and unexplainable. All I know is the Real garbage collectors are sometimes late picking up my garbage after I put it outside for them. -- Keith H -- www.keith-hair.net Steven Sacks wrote: No, it's not true. You're misunderstanding how weak listeners work, how anonymous functions work (you shouldn't use those anyway), and you're also misunderstanding how the garbage collector works. Whenever you addEventListener, immediately write a function that removes the event listener (such as a destroy method). If you get into this habit, you will never forget to do it and you'll never have this issue ever again. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Weak eventListener Problem
Ktu wrote: When the code below is run, the eventListener still fires. I was under the impression that it would not because the eventListener uses a weak reference, and thus get garbage collected. var sp:Sprite = new Sprite (); sp.addEventListener (Event.ENTER_FRAME, function (e:Event):void { trace(getTimer()); }, false, 0, true); sp = null; Am I just wrong? Yes and No. Yes, in that you assume that just removing all references will stop the listener right there and then. No, in that it will be eligible for garbage collection. But there is no guarantee when the garbage collection is performed, and until it has been performed, the listener will keep on working. If you need things to stop doing things _now_, turn them off yourself. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Weak eventListener Problem
That is true, however, this eventListener fires indefinitely. Garbage collection should pick it up after 30 seconds right? I have tried this on the main timeline, and in a document class, but GC never cleans up the object. Why? Ktu On Sat, Nov 7, 2009 at 5:29 AM, Henrik Andersson he...@henke37.cjb.netwrote: Ktu wrote: When the code below is run, the eventListener still fires. I was under the impression that it would not because the eventListener uses a weak reference, and thus get garbage collected. var sp:Sprite = new Sprite (); sp.addEventListener (Event.ENTER_FRAME, function (e:Event):void { trace(getTimer()); }, false, 0, true); sp = null; Am I just wrong? Yes and No. Yes, in that you assume that just removing all references will stop the listener right there and then. No, in that it will be eligible for garbage collection. But there is no guarantee when the garbage collection is performed, and until it has been performed, the listener will keep on working. If you need things to stop doing things _now_, turn them off yourself. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Weak eventListener Problem
Ktu wrote: That is true, however, this eventListener fires indefinitely. Garbage collection should pick it up after 30 seconds right? I have tried this on the main timeline, and in a document class, but GC never cleans up the object. Why? There is no set time when it will run. It runs when Flash thinks that it would be a good idea. The exact time is left intentionally unspecified so that they can change their minds if needed. There isn't even a guarantee that garbage collection will ever collect eligible objects. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Weak eventListener Problem
So I used the LocalConnection hack to force GC to run, and it cleaned up the object. I was not aware that GC might not run because there isn't enough of a reason to. If I had put this code into a fairly large application, GC would have more of a reason to run and thus probably end up cleaning up that object right? Ktu Lesson learned: You must remove all event listeners yourself. On Sat, Nov 7, 2009 at 12:36 PM, Henrik Andersson he...@henke37.cjb.netwrote: Ktu wrote: That is true, however, this eventListener fires indefinitely. Garbage collection should pick it up after 30 seconds right? I have tried this on the main timeline, and in a document class, but GC never cleans up the object. Why? There is no set time when it will run. It runs when Flash thinks that it would be a good idea. The exact time is left intentionally unspecified so that they can change their minds if needed. There isn't even a guarantee that garbage collection will ever collect eligible objects. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders