Note that there are some explanatory texts on larger screens.

plurals
  1. POMovieClip isn't removed from Dictionary
    primarykey
    data
    text
    <p>I have a Dictionary where I hold data for movieclips, and I want the data to be garbage collected if I stop using the movieclips. I'm using the weak keys parameters, and it works perfectly with other data, however I've run into a problem. </p> <p>This code works great:</p> <pre><code>var mc = new MovieClip(); var dic = new Dictionary(true); dic[mc] = 12; mc = null; System.gc(); System.gc(); for (var obj in dic) trace(obj); //this doesn't execute </code></pre> <p>But when I actually use the movieclip, it stops working:</p> <pre><code>var mc = new MovieClip(); var dic = new Dictionary(true); dic[mc] = 12; addChild(mc); removeChild(mc); mc = null; System.gc(); System.gc(); for (var obj in dic) trace(obj); //this prints [object Movieclip] </code></pre> <p>Why does this happen? Is it something I'm doing wrong? Is there a workaround?</p> <p>Edit: I know that for this specific example I can use <code>delete dic[mc]</code>, but of course this is a simplified case. In general, I don't want to manually have to remove the movieclip from the dictionary, but it should be automatic when I don't reference it anymore in the rest of the application.</p> <p>Edit2: I tried testing what Aaron said, and came up with just weird stuff... just iterating the dictionary (without doing anything) changes the behaviour:</p> <pre><code>var mc = new MovieClip(); var dic = new Dictionary(true); dic[mc] = 12; addChild(mc); removeChild(mc); mc = null; for (var objeto in dic) {} // &lt;-- try commenting out this line addEventListener('enterFrame', f); // I print the contents every frame, to see if // it gets removed after awhile function f(evento) { System.gc(); System.gc(); for (var objeto in dic) trace(objeto); } </code></pre> <p>This keeps printing [object Movieclip] every frame, unless I comment out the indicated line, where it doesn't print anything.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload