How do I destroy variables in Flex?

This question comes in from Gina, and it is a follow up to my series on Cairngorm.

From your blog Learning Cairngorm (Part 6) Dealing with the Singleton You mentioned the following:

"Unless you write code to "Destroy" / get rid of the stuff you are storing in the ModelLocator, it will hang out there for as long as your application is in use. In some cases this is fine. In others it can be wasteful. Loading and storing too much data could lead to memory issues."

Right now I am working on pretty big application and having similar problem. Is there any simple and efficient way to destroy the data in the ModelLocator? I have at least total of 1000 variables, these variables are declared in several different ModelLocator files.

It does sound like you have a lot of variables. I think first you have to understand what a variable is. A variable is a pointer to a spot in memory. What does that spot in memory hold? It could hold anything, such as an integer, a string, a value object, an instance of a List class, the Flextras AutoCompleteCombobox, or a full array of images.

Memory and performance problems are probably due to content that resides in the memory spaces that your variables point to. To get rid of this stuff, you need stop the variable from pointing to it. Something like this should suffice:


myVariable = null;

The the garbage collection in the Flash Player will find all the blocks of memory that are not referred to and clean them up.

What fun to be answering a programming question again. I don't get as much time to write as I'd like given I now run two podcasts.

You can always ask your question to me here, or stop by a Flextras Friday Lunch session and ask me in person.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.