- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
altought i prefer explicit cleaning over weak references, i found them usefoul in some situations
I actually use weak ref and also remove them manually. But it feels good to know an event listener won’t screw your app if you forget to remove it.
So is not using it just faster to write? I’m still wondering the advantages of not using it.
It might actually be a case of weak references having an advantage or disadvantage when compared to using strong references. There might be times when using weak references are better fitted to the situation than strong references, as far as clean up goes. And likewise with strong references. I suppose it matters how you code that would determine the benefits of either, or more so at, the advantages of using either. And it would require understanding how they affect the situations of coding to know of those advantages.
- Sold between 100 000 and 250 000 dollars
- Author had a File in an Envato Bundle
- Has been a member for 4-5 years
- Author had a Free File of the Month
- Won a Competition
- Author was Featured
- Item was Featured
- Bought between 10 and 49 items
Do you mean that we cant use “this” in a function anymore?no, i mean when using smt like this
Events.add(player,StreamEvent.INFO,init)there’s no way for Events.add function to know parent object for “init” method.
try this article by gskinner:
http://gskinner.com/blog/archives/2006/07/as3_weakly_refe.html
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
I’ve taken a look at some tween engines and was always confused to why they used Dictionaries without weak ref. I think I found the answer and have finally found a legitimate reason to not use weak references:
Increased speed when adding an event listener probably doesn’t outweigh the benefits of using weak ref though. I guess it would depend on the project.
But…...while a developer designing recyclable Class and manually clear references/listeners, I can’t see the benefits of using weak reference. Using weak reference just make it unstable and harder to test memory usage while developing.
For example, while monitoring memory usage of a instance which should be destroyed in plan, maybe we forget (we shouldn’t) calling it’s destroy method but somehow it is cleared by using weak reference, then we think “ah, ok looking like we have done everything necessary”, and this minor error will stay in project unnoticed.
Let’s say using weak reference only when we not sure when this instance will be destroyed, but in my experience it is really hard to find such situation ( adding listeners in timeline frame ? maybe, but this should be avoided ).
But this is just my opinion 
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
Let’s say using weak reference only when we not sure when this instance will be destroyed,
this is how I’m going to use them from now on. Before I just always used them because I didn’t see any reason not to (in my opinion you shouldn’t really need an event listener to keep an object alive).
- Microlancer Beta Tester
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 50 and 99 items
- Exclusive Author
- Has been a member for 3-4 years
- Item was Featured
- Sold between 100 000 and 250 000 dollars
Just wasted 1-2 hours of investigation because of this. The listeners disappeared on fullscreen activation.
I am not gonna use weak references again. Better with removeEventListener on REMOVED _FROM_STAGE
Just a warning towards my fellow developers
.
Interesting. I’ll have to look into some of my older code because I used to use weak references more often back when Crackaz mentioned them to me for the first time. If the listeners do get removed upon Fullscreen activation, as you put it, then it must explain some bugs I was getting.
- Microlancer Beta Tester
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 50 and 99 items
- Exclusive Author
- Has been a member for 3-4 years
- Item was Featured
- Sold between 100 000 and 250 000 dollars
Aw_Shucks said
Interesting. I’ll have to look into some of my older code because I used to use weak references more often back when Crackaz mentioned them to me for the first time. If the listeners do get removed upon Fullscreen activation, as you put it, then it must explain some bugs I was getting.
lol I feel sorry for you then.
I only used weak reference on non important / small / added dynamically stuff
