A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: null -ing stuff Help

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    28

    null -ing stuff Help

    if I have:

    Actionscript Code:
    public class Gate extends MovieClip {
             
           
                private var sC1 = new SoundChannel;
            private var dO = new Sound(new URLRequest("open.mp3"));
            private var dC = new Sound(new URLRequest("close.mp3"));
            private var night = new Sound(new URLRequest("night.mp3"));
            private var gateContainer:* = new MovieClip();
            private var DoorL:* = new doorL();
            private var GtGlow:* = new gtGlow();
            private var ent:*= new invisB();
            private var blr:* = new BlurFilter(5,5,1);
            private var glo:* = new GlowFilter(0xE5DADA,1,10,10,3,3,false);
            private var DoorRbmd:BitmapData = new doorR(0,0);
            private var GateFrbmd:BitmapData = new gateFr(0,0);
            private var DoorR:Bitmap = new Bitmap(DoorRbmd);
            private var GateFr:Bitmap = new Bitmap(GateFrbmd);
            private var ceoFen:* = new Sprite();
            private var Fen:*= new fen();
            private var fenCast:* = new castL();
            private var sta:* = new staklo();
            private var GlowF:* = new glowF();
            private var arrayMc:Array;
    //.. rest of the class

    and after Im done with this class (Gate), and click to another(Page1), can I do:

    Actionscript Code:
    arrayMc = ceoFen = DoorR = DoorL = Fen = fenCast =
                    ent = GateFr = GtGlow = GateFrbmd = GlowF = sta =
                    gateContainer = blr = glo = dO = dC = night = null;

    I mean it works I guess, profiler doesnt show them lingering around in Page1, but is this the right way to remove stuff and save memory ?

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    That's technically valid albeit a bit sloppy.
    You cannot manually remove items from memory, only the garbage collector can do that. Nullifying merely makes things eligible for garbage collection. The key GC eligibility is removing all references. Nullifying the parent class instance removes it as the only reference to its properties (in most cases) thus eliminating the need to clear each property individually. You of course have to stop all playing movie clips, remove any listeners, shut down all streams any other logical activity before nullifying the parent. Having a public function called destroy() is common practice.

    myParentClass.destroy();
    myParentClass = null;

    Newer versions of the flash player are better at doing a lot of this along with letting you trigger the garbage collector on command but until you're familiar with how that works, this is a good practice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center