CodeCanyon

weak references

5008 posts The Dude Abides
  • United States
  • Elite Author
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
+4 more
CodingJack says
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.

4247 posts
  • Attended a Community Meetup
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 10 000 and 50 000 dollars
  • United States
Aw_Shucks says

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.

1844 posts
  • Elite Author
  • 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
  • Bought between 10 and 49 items
+4 more
bitfade says
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.
4 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 and 100 dollars
sk_86 says
5008 posts The Dude Abides
  • United States
  • Elite Author
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
+4 more
CodingJack says

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:

http://stackoverflow.com/questions/1235195/what-is-are-the-disadvantages-of-using-weak-references-in-eventlisteners-in-a

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.

111 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 1 000 and 5 000 dollars
  • Taiwan
savorks says

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 :)

5008 posts The Dude Abides
  • United States
  • Elite Author
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a Free File of the Month
+4 more
CodingJack says

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).

1422 posts
  • Microlancer Beta Tester
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 100 000 and 250 000 dollars
+2 more
ZoomIt says

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 :P.

4247 posts
  • Attended a Community Meetup
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 10 000 and 50 000 dollars
  • United States
Aw_Shucks says

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.

1422 posts
  • Microlancer Beta Tester
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 100 000 and 250 000 dollars
+2 more
ZoomIt says

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

by
by
by
by
by