take a look at the following code
var a = new View();
a = null;
....
class View {
private var clip: MovieCLip
public function View() {
clip.addEventListener(...)
}
}
will a be in memory after a = null? Does addEventListener adds a strong refernce?
Since all the references to
clipare withina, GC will pick up both objects and cleanly remove them.I’ve taken your example and used an ENTER_FRAME listener to create new
Views in the same way you did:If, however, clip were added to the stage, then it would continue to exist, and
awould also not be removed:You can use the
useWeakReferenceparameter ofaddEventListenerto prevent this from happening.