# When to null and when to delete

**URL:** <https://forum.kirupa.com/t/when-to-null-and-when-to-delete/296117>\
**Category:** flash\
**Created:** [September 9, 2009, 6:22pm UTC](https://forum.kirupa.com/t/when-to-null-and-when-to-delete/296117 "2009-09-09T18:22:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![plumpnation](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/plumpnation/32/1929_2.png) [@plumpnation](https://forum.kirupa.com/u/plumpnation)\
**Post date:** [September 9, 2009, 6:22pm UTC](https://forum.kirupa.com/t/when-to-null-and-when-to-delete/296117/1 "2009-09-09T18:22:06Z")

</div>

Hi everyone,

I recently bumped into an issue in the Flash IDE that you may be able to shed some light on for me.

As I drag a movieclip around the stage, an enterFrame event listener is fired.  
For each enterFrame that fires, a point is placed onto the stage, stored into an array and the event.updateAfterEvent() method is called.

var p:MyPoint = new MyPoint(x,y);  
parent.addChild§;  
myArray.push§;

which is a MovieClip in my library containing a cross.

On stopDrag, the enterFrame is removed. The myArray:Array is for each looped and the MyPoint objects are removed from the stage.

for each(var p:MyPoint in stack){  
//trace out the class type, cool huh;  
//trace(getQualifiedClassName§);  
trace(p.name);

```
            parent.removeChild(p);
        }

```

The array is reset.

myArray = [];

My question is coming. In the IDE, when I compile to test, after a few drags the whole thing starts to grind and churn, making me think there is a garbage collection issue, and that the removeChild was not enough to get rid of the references to these MovieClips.

I dug around in google for a while, read some Senocular pages (you know how it is), and found that you need to null references to the MovieClips.

I like encapsulation, but if I have to remove the MovieClips from the parent inside my class, how can I then null them. I can’t get to them any more through the parent.

I tried this:

for each(var p:MyPoint in stack){  
//trace out the class type, cool huh;  
//trace(getQualifiedClassName§);  
trace(p.name);

```
            parent.removeChild(p);
            p = null;
        }

```

But it still churned.

Then

I debugged the app, causing the movie to play in the Flash Player outside of the IDE, and the movie ran smoothly without any grinding or slowing down.

So, question 1 is this:  
Has anybody experienced the same slowing down in IDE but not in standalone Flash player?

And question 2 is this:  
When should you use ‘delete movieClip;’ and when should you use movieClip = null?  
I read about class properties and dynamic references or something, but I don’t understand what the difference is?

Any help would be greatly appreciated, thanks for reading!

Plumper than thou
