Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?
Yep I'm with you – it definitely makes sense to have it default to false...would lead to a lot of unexpected behaviour especially for beginners if it defaulted to true. Piers On 8 Feb 2010, at 14:41, Merrill, Jason wrote: > So what would be wrong with always using strong references and always > deleting them when you're done? That's what I do - I feel like I have > more control over what's going on in my code that way. Sure, if I > forget to remove it, it could still be out there, but if you get in the > habit of always removing them when they are no longer needed, it's > second nature. To me, it makes sense that it defaults to false because > of the problems already mentioned. > > > Jason Merrill > > Bank of America Global Learning > Learning & Performance Soluions > > Join the Bank of America Flash Platform Community and visit our > Instructional Technology Design Blog > (note: these are for Bank of America employees only) > > > > > > -Original Message- > From: flashcoders-boun...@chattyfig.figleaf.com > [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of W.R. de > Boer > Sent: Monday, February 08, 2010 5:06 AM > To: Flash Coders List > Subject: Re: [Flashcoders] Re: is it ever ideal to NOT use weak > references? > > Yes, but it can also cause a lot of trouble when used. I have had causes > where the event listener got deleted too early and then you spend a lot > of time finding the issue. And that was not with the Loader-class and > Event.COMPLETE or others. > ___ > 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] Re: is it ever ideal to NOT use weak references?
So what would be wrong with always using strong references and always deleting them when you're done? That's what I do - I feel like I have more control over what's going on in my code that way. Sure, if I forget to remove it, it could still be out there, but if you get in the habit of always removing them when they are no longer needed, it's second nature. To me, it makes sense that it defaults to false because of the problems already mentioned. Jason Merrill Bank of America Global Learning Learning & Performance Soluions Join the Bank of America Flash Platform Community and visit our Instructional Technology Design Blog (note: these are for Bank of America employees only) -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of W.R. de Boer Sent: Monday, February 08, 2010 5:06 AM To: Flash Coders List Subject: Re: [Flashcoders] Re: is it ever ideal to NOT use weak references? Yes, but it can also cause a lot of trouble when used. I have had causes where the event listener got deleted too early and then you spend a lot of time finding the issue. And that was not with the Loader-class and Event.COMPLETE or others. ___ 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] Re: is it ever ideal to NOT use weak references?
Yes, but it can also cause a lot of trouble when used. I have had causes where the event listener got deleted too early and then you spend a lot of time finding the issue. And that was not with the Loader-class and Event.COMPLETE or others. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?
Piers Cowburn skrev: That way, if I forget to remove the event listener in a destroy method or whatever, it should still end up eligible for GC. Cases where the event doesn't fire because a weak reference was used only happen if there are no strong references anywhere else, so the object rightly gets GC'd One cannot be sure that the object get GC'd right away or at all. lets say you have a movieclip with a weak ENTER_FRAME listener on itself. the movieclips references are all removed. The ENTER_FRAME could still be dispatched, and is out of your control. However i think it's a good practice to use weak eventlisteners. /Christoffer ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Re: is it ever ideal to NOT use weak references?
Oooh, OK, it is also the way I do it. I didn't understand the difference between strong and weakly. Not my native language, I am Dutch. Thanks for clearing it to me! -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks Sent: zondag 7 februari 2010 23:34 To: Flash Coders List Subject: Re: [Flashcoders] Re: is it ever ideal to NOT use weak references? function onComplete(event:Event):void { event.target.removeEventListener(Event.COMPLETE, onComplete); } Easy peasy. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2673 - Release Date: 02/07/10 08:22:00 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?
I use a strong listener only when I know I'm not holding a reference to the dispatcher anywhere else. In all other cases, i.e. if I know I'm going to be keeping the dispatcher on the display list (if it's a DisplayObject) until I no longer need it, or if I know I'm storing a reference the dispatcher somewhere in a parent class or a dictionary or something, I always use a weak reference. That way, if I forget to remove the event listener in a destroy method or whatever, it should still end up eligible for GC. Cases where the event doesn't fire because a weak reference was used only happen if there are no strong references anywhere else, so the object rightly gets GC'd Piers On 7 Feb 2010, at 13:27, Cor wrote: > Could you give an example of the way you use the strong listener? > > TIA > > -Original Message- > From: flashcoders-boun...@chattyfig.figleaf.com > [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks > Sent: zondag 7 februari 2010 4:32 > To: Flash Coders List > Subject: Re: [Flashcoders] Re: is it ever ideal to NOT use weak references? > > function loadImage():void > { > var loader:URLLoader = new URLLoader(); > loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); > loader.load(new URLRequest(url)); > } > function onComplete(event:Event):void > { > trace(event); > } > > Guess what never fires? If you guessed "onComplete", you win the prize. > > Now imagine that it defaulted to true and you wrote the same thing leaving > off > the false, 0, true. You would have no idea why it didn't work. > > It didn't work because the loader was cleaned up by GC as soon as the > loadImage() function reached the end. > > Generally, I only use weak listeners with Timers and enter frame listeners. > Everything else I use strong listeners and write a remove listener for them > when > they're expected to unload or be garbage collected at some point. > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.733 / Virus Database: 271.1.1/2673 - Release Date: 02/07/10 > 08:22:00 > > ___ > 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] Re: is it ever ideal to NOT use weak references?
function onComplete(event:Event):void { event.target.removeEventListener(Event.COMPLETE, onComplete); } Easy peasy. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?
Yes, I am doing the same because the trouble weak event listeners can cause. > function loadImage():void > { > var loader:URLLoader = new URLLoader(); > loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); > loader.load(new URLRequest(url)); > } > function onComplete(event:Event):void > { > trace(event); > } > > Guess what never fires? If you guessed "onComplete", you win the prize. > > Now imagine that it defaulted to true and you wrote the same thing leaving > off > the false, 0, true. You would have no idea why it didn't work. > > It didn't work because the loader was cleaned up by GC as soon as the > loadImage() function reached the end. > > Generally, I only use weak listeners with Timers and enter frame > listeners. > Everything else I use strong listeners and write a remove listener for > them when > they're expected to unload or be garbage collected at some point. > ___ > 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] Re: is it ever ideal to NOT use weak references?
Could you give an example of the way you use the strong listener? TIA -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks Sent: zondag 7 februari 2010 4:32 To: Flash Coders List Subject: Re: [Flashcoders] Re: is it ever ideal to NOT use weak references? function loadImage():void { var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.load(new URLRequest(url)); } function onComplete(event:Event):void { trace(event); } Guess what never fires? If you guessed "onComplete", you win the prize. Now imagine that it defaulted to true and you wrote the same thing leaving off the false, 0, true. You would have no idea why it didn't work. It didn't work because the loader was cleaned up by GC as soon as the loadImage() function reached the end. Generally, I only use weak listeners with Timers and enter frame listeners. Everything else I use strong listeners and write a remove listener for them when they're expected to unload or be garbage collected at some point. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2673 - Release Date: 02/07/10 08:22:00 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?
Steven Sacks wrote: Guess what never fires? If you guessed "onComplete", you win the prize. You do realize that this is not guaranteed, right? It might not fire, but it may also do fire. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?
function loadImage():void { var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.load(new URLRequest(url)); } function onComplete(event:Event):void { trace(event); } Guess what never fires? If you guessed "onComplete", you win the prize. Now imagine that it defaulted to true and you wrote the same thing leaving off the false, 0, true. You would have no idea why it didn't work. It didn't work because the loader was cleaned up by GC as soon as the loadImage() function reached the end. Generally, I only use weak listeners with Timers and enter frame listeners. Everything else I use strong listeners and write a remove listener for them when they're expected to unload or be garbage collected at some point. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] Re: is it ever ideal to NOT use weak references?
sorry i'm an idiot it's all over google my apologies http://onflash.org/ted/2008/09/useweakreferencesboolean-false.php On Fri, Feb 5, 2010 at 9:33 PM, jared stanley wrote: > wondering why it defaults to false, seems like it really only affects GC, > so you'd want it set to true by default but maybe i'm missing something. > > jared > > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders