# Getting rid of variables from memory?

**URL:** https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492
**Category:** flash
**Created:** [June 26, 2008, 3:45pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492 "2008-06-26T15:45:48Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)
#### Post date: [June 26, 2008, 3:45pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/1 "2008-06-26T15:45:48Z")

</div>

I know this might seem overkill but how come this throws a strict warning?

var hi2u:int = 25;

// code

hi2u = null;

Was under the impression that variables that are nulled are subject to the GC sweep.

---

<div class="post-metadata">

### Author: ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)
#### Post date: [June 26, 2008, 4:02pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/2 "2008-06-26T16:02:58Z")

</div>

Integers cannot be set to null. They’ll be destroyed whenever they go out of scope.

---

<div class="post-metadata">

### Author: ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)
#### Post date: [June 26, 2008, 4:07pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/3 "2008-06-26T16:07:43Z")

</div>

Ic, thanks.

---

<div class="post-metadata">

### Author: ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)
#### Post date: [June 26, 2008, 6:38pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/4 "2008-06-26T18:38:03Z")

</div>

An integer can’t have the value of NaN, if you set one to NaN it will just be set to 0 instead. Only Numbers can be NaN.

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 26, 2008, 6:41pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/5 "2008-06-26T18:41:24Z")

</div>

So when exactly is it considered ‘out of scope’, in your understanding?

---

<div class="post-metadata">

### Author: ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)
#### Post date: [June 26, 2008, 6:48pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/6 "2008-06-26T18:48:25Z")

</div>

The way I understand it… if it’s a local variable then it’s out of scope when you leave the function the variable is defined in.

If it’s a class variable then it should be destroyed whenever the instance of the class it is defined in gets garbage collected.

An integer is a relatively small size anyway. In theory it should be about the same size as a reference pointer. You’ll never get huge memory leaks or anything from integers. They shouldn’t ever prevent an object from being garbage collected either.

That’s how it works as far as I know. I’d have to know more about how the Flash Player actually works to tell you exactly what happens. Hopefully Senocular or somebody with inside knowledge could correct anything I wrong about.

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [June 26, 2008, 7:01pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/7 "2008-06-26T19:01:49Z")

</div>

Yeah, clearly integers aren’t a big deal, but it’s interesting to ponder. A class should get garbage collected when it’s not on the stage, being listened to, doing anything at all, right? All the GC stuff is not very transparent. :-/

---

<div class="post-metadata">

### Author: ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)
#### Post date: [June 26, 2008, 7:11pm UTC](https://forum.kirupa.com/t/getting-rid-of-variables-from-memory/264492/8 "2008-06-26T19:11:13Z")

</div>

Right. Whenever an object is not in the display list, has no event listeners and has doesn’t have a references pointing to it it should be garbage collected.

Of course it gets weirder than that since you’ve got issues with self-referencing objects, events which doesn’t stop garbage collection, etc…

There are actually two different kinds of garbage collection which are performed. It’s pretty complicated stuff.
