RemoveChild and Garbage Collector

I am still fuzzy on the Actionscript 3 framework.
If I remove a child from a container, is the removed child
automatically eligible for the garbage collection?
If not – what should I do to make it eligible?
If yes – what can be done to prevent it from being
permanently deleted should I need it?
container.removeChild(myDisplayObject)
Thank you!

kglad,
Thank you very much for you response - things are much
clearer now.
I am trying to figure out some standard ways to deal with
unneeded objects. I am relatively new in OOP (and my OOP education
comes from JS and Flash) and it is not very obvious to me yet how
to approach garbage collection in general (and I realize how
important this kind routine is).
If this is not very time consuming - could you please share
some bullet points of how you do that. Do you have, say, a class
that performs clean up routine for all the objects or, may be, each
class has to have some method that cleans up after it? Also, what
would be an optimal way to keep track of the objects (some central
depository/library) so that one can find them easily. I've noticed
that there is a new class Dictionary in AS3 - can it be useful for
this task?
I know that I want too much and I need to pick up a book or
two on OOP but, still, I like to hear developers' experiences not
only because I tend to take short cuts but also because in many
cases what experience dictates is much more useful than academical
elaborations.
Again, thank you very much,
Andrei

Similar Messages

  • Clear method and Garbage Collector

    Hi Gurus,
    Does the Clear method (hashtable, vector etc..) is a good option for garbage collection ?
    In other words, if I have a vector V with 100 elements and I perform a V.clear(), am I sure that the 100 elements are now candidates for the Garbage Collection ?
    Or is it better to write a loop performing a NULL assignment for each element of the vector ?

    Hi schapel,
    I know it's not a good idea to force the garbage collector, but let me explain what I am confronted with.
    (FYI, I didn't write the source code. Comes from a 3rd party)
    The aim is to build a jsp page which is the list of the files contained in a web server directory.
    I have a "Directory" class, and a "File" class. To build the jsp, each directory of the webserver is represented by a directory class, and each file, ...by a file class.
    To simplify, when the tree structure of the web server is build in memory, I create a jsp page to list the files, and then, I do not need the vector anymore. But the vector can be quite huge and each client will build his own vector at the begening of his session (and will never use it again during the session).
    Don't you think it's usefull in that situation to free some memory ?

  • EMCC and Garbage Collector

    We have 2 CUCM clusters connected via an ICT. We are migrating users from CM8.6 to CM10.5. During the migration we are changing Users AD attributes so that they disappear from CM8. As this marks the user as Inactive in CM8 (and deletes after 24hrs) this prevents the User from logging into CM10 with EMCC.
    Is there a way around this?
    ie force the garbage collector to run immediately and delete the user
    or remove certain fields in CUCM 8 against the user so that they can login using CUCM10 credentials?
    Thanks
    Rich

    I think you can do something clever here. You can convert the inactive user on cucm 8 back to a standard cucm user and then delete them. This way you can control when to remove the user instea dof waiting for garbage collection. You become your own garbage man :)
    You can conver the users back to standard CUCM users using sql query update...Ths is easy to do
     run sql update enduser set status=1 ( this is the general command to make all users standard cucm users..you don't want to run this..)
    Use this command to make specific users active. You need to use the users extension to filter which user gets converted to standard cucm user
    run sql update enduser set status=1 where telephonenumber like ‘2%’
     This command will update users with extension beginning with 2
    or
    run sql update enduser set status=1 where telephonenumber = '2001'
    This will convert user with extension 2001 to a standard cucm user
     To make sure you got all the users you can use the command
    run sql select * from enduser where status=0
     This should return zero entry. If you find any user there then use the update command on those users

  • I have a memory leak, objective-c 2.0, and garbage collector...

    the code i am using is a modification of the code/problem found in "Cocoa with Objective-C", chapter 3.
    i have tried to use the objective-c 2.0 garbage collector methodology, using @property, @synthesize, etc. when i run the code as listed below i get a leaking message.
    [Session started at 2008-02-01 23:33:37 -0500.]
    2008-02-01 23:33:38.070 SongsFoundationTool[28876:10b] * _NSAutoreleaseNoPool(): Object 0x2040 of class NSCFString autoreleased with no pool in place - just leaking
    Stack: (0x96b10178 0x96a3e0f8)
    2008-02-01 23:33:38.075 SongsFoundationTool[28876:10b] Song 1: We Have Exposive
    2008-02-01 23:33:38.076 SongsFoundationTool[28876:10b] * _NSAutoreleaseNoPool(): Object 0x2060 of class NSCFString autoreleased with no pool in place - just leaking
    Stack: (0x96b10178 0x96a3e0f8)
    2008-02-01 23:33:38.078 SongsFoundationTool[28876:10b] Song 2: Loops of Fury
    The Debugger has exited with status 0.
    when i include the commented out section, in the implementation file section, the description method, and use song1 and song2, in main, instead of song1.name and song2.name the program seems to run fine.
    The Debugger has exited with status 0.
    [Session started at 2008-02-01 23:38:24 -0500.]
    2008-02-01 23:38:24.375 SongsFoundationTool[28936:10b] Song 1: We Have Exposive
    2008-02-01 23:38:24.379 SongsFoundationTool[28936:10b] Song 2: Loops of Fury
    The Debugger has exited with status 0.
    please help me understand what's happening here.
    also, why was it necessary to use
    @property(copy, readwrite) NSString *name;
    @property(copy, readwrite) NSString *artist;
    instead of
    @property(readwrite) NSString *name;
    @property(readwrite) NSString *artist;
    thanks everyone, the code is below.
    // ....................... header file ...............
    #import <Cocoa/Cocoa.h>
    @interface Song : NSObject {
    NSString *name;
    NSString *artist;
    @property(copy, readwrite) NSString *name;
    @property(copy, readwrite) NSString *artist;
    @end
    //.................... the implementation file ..................
    #import "Song.h"
    @implementation Song
    @synthesize name;
    @synthesize artist;
    -(NSString *) description
    return [ self name ];
    @end
    //................................ main............................
    #import <Foundation/Foundation.h>
    #import "Song.h"
    int main (int argc, const char * argv[]) {
    Song *song1 = [ [ Song alloc ] init ];
    song1.name= @"We Have Exposive" ;
    [ song1 setArtist: @"The Future Sound Of Londown" ];
    Song *song2 = [ [ Song alloc ] init ];
    [ song2 setName: @"Loops of Fury" ];
    [ song2 setArtist: @"The Chemical Brothers" ];
    // Display Object
    NSLog( @"Song 1: %@", song1.name );
    NSLog( @"Song 2: %@", song2.name );
    // include statements below if -description method is uncommented
    // then comment out the two statements above. no memory leak if the code
    // is used from the statements below and - description is not commented out and
    // the two NSLog statements above are commented out.
    NSLog( @"Song 1: %@", song1 );
    NSLog( @"Song 2: %@", song2 );
    return 0;
    }

    Normally, your main only has a call to NSApplicationMain(). If you aren't doing a traditional MacOS X application, you will still want at least NSApplicationLoad() to get enough of the runtime to avoid those messages.
    I don't know for sure about the syntax of Objective-C 2.0. That stuff is all new. What error message are you getting that indicated that (copy, readwrite) is required? Could you provide a link to the actual example source? I did a quick check and assign and readwrite are the defaults. It is possible that readwrite by itself makes no sense. But I'm just guessing.

  • CORBA and garbage collector

    Hi,
    I�m writing a server with a method create(), which returns a new object supplying a home banking service for the clients.
    My question is : when a given client has finished with the home banking object, do I need to call the gc, or is there an efficient one with CORBA (a kind of distributed garbage collector) ?
    Thank you in advance

    Maybe you heard about Distributed Garbage Collector (DGC)? Don't rely on this, since IIOP does not support this. Use PortableRemoteObject.unexportObject() to make remote objects that are no longer in use available for garbage collection.
    Bert

  • Primitives and garbage collector

    Hi everyone,
    Do primitives get garbage collected?
    Is it recommended to set all references to null in a classes finalize method?
    Thanks

    Do primitives get garbage collected?No.
    Is it recommended to set all references to null in
    in a classes finalize method?No, there is no point in doing that.

  • Swing components and the garbage collector

    How much care does one need to take with swing components, with reference to running out of stack space? I ask because I'm writing a system for an automotive parts company, and the company tends to not reboot the machines very often...
    Anyway... if a JFrame is closed, is it and all its components marked for GCing? Do I need to call the dispose method, or is this part of the default close behaviour? Or is there something else entirely?
    Cheers

    In class that calls for .setVisible(false) of one JFrame u MUST call
    for dispose() method.
    so
    myFrame.setVisible(false)
    myFrame.dispose()
    myFrame = null // to help the garbage collector
    If u have classes that becames from JFrame (or JDialog) u can
    invoke in its constructors:
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
    This makes uncecessary to call for dispose() method explicetly.
    If u do not have this kind of classes u can invoke this method
    after u have create your JFrame
    JFrame myFrame = new JFrame();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
    The most important thing is REMOVE ALL LISETNERS that u have added, so, if u have classes that becames from JFrame u can ovverride
    the dispose method to do that
    eg
    public void dispose()
    super.dispose()
    removeActionListener(.....)
    and so on
    If u do not have this kind of classes u must remove all listeners u have
    added before u invoke the setVisible(false) method.
    Regards

  • Garbage Collector and verbose GC

    Hi, we are getting strange behavior with the garbage collector if the verbosegc is enabled. The gc still report it is collecting memory but none is ever freed. If the option is not enabled the problem disapear. Has anyone experience something similar?
    We are running on Sun 5.8 with weblogic 5.1 sp 8 and jdk 1.2.2_09

    Can you post some of the verbosegc output? Output with -XX:+PrintGCDetails might
    help a little more.

  • Garbage collector and JPEG decoder

    Hi,
    I have a problem with the garbage collector decoding JPEG images received on a TCP socket. The process works but each time that I have to decode an image I have to create a new decoder, this causes that the garbage collector starts to work constantly looking for memory. When the gc starts to work the streamed images almost stop since the gc takes all the process.
    Here is the code that has the problem. On this code you can see that I create a new ByteArrayInputStream and a MediaTracker, but I know how reuse this objets, the problem is on the decoder.
    Does any one have an idea of how to solve it?
    Thanks
    public void cargarImagen(Visualizador vision,
                                  Cabecera cabImg,
                                  boolean completa,
                                  boolean grabar,
                                  boolean pantCIF,
                                  JFrame1 jf1)throws Exception{
            Visualizador aux;
            ByteArrayInputStream byis = new ByteArrayInputStream(s1.buffer);
            try{
                    decoder=JPEGCodec.createJPEGDecoder(byis);
                    try{
                           // decode
                                                   vision.image_Webcam=decoder.decodeAsBufferedImage();
                    }catch(ImageFormatException b){
                      System.out.println("Incorrect image format");
                    }catch(Exception a){
                      System.out.println("Incorrect image");
                    mediaTracker_track = new MediaTracker(vision);
                    mediaTracker_track.addImage(vision.image_Webcam, 0);
                 mediaTracker_track.waitForID(0,500);
            }finally{
                      byis.close();
            if(mediaTracker_track.statusID(0, false) == MediaTracker.COMPLETE){
                  vision.repaint();
             else{    /* incorrect image */
                  vision.image_Webcam = null;
                  System.out.println("Discarded image");
    }

    I think that this is not the case. Images come from a TCP connection and the application start to read the next image from the socket when the previous one has been decoded and painted.
    So, images are not stored on memory and the received images rate depens on how fast is the application reading images from the socket.
    However, it is a good idea to start gc before getting next image, the average rate will decrease but it will avoid the "jumps" on visualization.

  • Garbage collector and JVM

    is garbage collector is part of JVM or it is part of our program process.
    ie ... if we are having 3 programs running at the same time will we have one garbage collector for them or we will have 1 each ofor each process.
    what is the priority of the garbage collector as a process.

    GC is a part of JVM. GCs from different JVMs never
    intersect.hmm.
    So if i am having 3 programs of java running on one machine. how much JVM will i be running ... i guess one. so will they share one GC ???
    what is the priority of GC at process level???

  • SystemManager and Garbage Collection

    Hi everyone, I have a question regarding the SystemManager and Garbage Collection. I have and application that loads in its assets via a swc created in Flash. In that swc I have different MovieClips that act as the different screens of my application each one being tied to its own custom class. For example one MovieClip is a login screen another is the main menu etc. These screens contain components, text fields and animations. The problem that I am having is when I move from one screen to the other the garbage collector is not cleaning up everything. There are still references to the MovieClips that have animations for example. So even though I remove the screen via removeChild and set the variable reference to that object to null it is not releasing the MovieClips. When I pull it up in the profiler it shows me that SystemManager is holding references to them. Also if I debug the applicaion and look inside the instance of the MovieClip I can see that the private property "listeners" has values, but I am not adding listeners. It appears that the SystemManager is adding listeners. Does anyone know how I can clear these listeners or force the SystemManager to release these items. Any ideas or help would be greatly appreciated. I am fairly new to dealing with memory management and garbage collection in Flex. I am using Flash CS4 to create the swc and Flash Builder 4 Beta with the 3.4 framework and Flash Player 10 to create the app. If you need me to clarify any of this please let me know. Again any help or ideas on where to go from here would be great!

    This chain says that the focusManager is referencing UserMenu.  Is there a default button or focusable objects in UserMenu and references from UserMenu to the objects in question?
    BTW, the CS4 fl.managers.FocusManager and any fl.. classes are incompatible with Flex, so make sure you're not using them in your MovieClips.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Garbage Collector Questions

    Howdy all,
    I've got a few questions about flash's garbage collector.  I'm building a  game and have all elements in a container sprite called _gameContainer.
    _gameConatiners contains other sprites such as _hudContainer which  contains more containers such as _gameoverContainer, _menuContainer,  etc.  So there's a whole hierarchy of containers that are all contained  in _gameContainer which is added directly to the document class (not the  stage btw).
    So the whole thing should basically be Stage -> Document Class -> _gameContainer -> etc.
    When the player loses or wants to restart the game, I'm removing all  event listeners (which are defined as weak, but still rather make sure  there's no loose ends), stopping all music/sounds, removing  _gameContainer from the stage, and then setting _gameContainer to null.   From there I am re-calling my init function which creates everything  (_gameContainer, and everything inside of it, as well as creating all the  standard eventlisteners).
    Am I doing everything upside down?  Is this *a* proper way of restarting  a game?  Mind you I dont say "the" proper way since I'm sure there's a  hundred different ways to do this.
    Also, on a separate note... If I have something such as an enemy, I keep all  enemy logic contained in the class linked to the movieclip on the  stage.  Who should be calling add/removechild?  Should I be using a  factory method that takes care of all this, or should I have the engine  create the enemy, and then have the enemy remove itself from stage?   Currently I'm using a mix of both, but generally I'll have a function in  the engine/caller add it to stage, then have the class have an  ADDED_TO_STAGE event listener.  When it comes time to remove the class, I  have it call it's own removeself function such as: (_container is a  reference to it's container as mentioned above such as _hudContainer)
    protected function removeSelf():void
        if(_container.contains(this)) {
            _container.removeChild(this);
        _container.parent.parent.dispatchEvent(new Event(Engine.START_GAME));
    Thanks!

    Wonderful question Travisism.
    The garbage collection is strange.  First I'm curious why you lump displayObjects into _gameConatiners.  Does _gameConatiners get added to the stage at any point?  Why not just add the proper hud at the point its required?
    Anyhow.  By removing listeners ,removeChild(_gameConatiners), and setting _gameConatiners=null does not mean these classes are killed.  null only marks the memory locations as having no more references to them.  When this occurs these objects may be removed from memory.  Why do I say may, that is because it takes a specific amount of memory utilized to trigger the garbage collection.
    Now just merely setting _gameConatiners=null may not ever kill your objects off.  You would be required to profile this and make sure they are dieing properly.  From the sounds of it you have a lot of inner children.
    There is reason to believe that in some cases, when an object is removed from the main stacks that its children will be removed as well.  Though, if the inner workings are so large, often the objects within referencing each other effects the way the garbace collection is stating they are still in use.  Thus keeping these objects alive.
    Its always best to kill off every reference being used.  You can do this by ensuring each object in your movieClip class declared a kill method, and continue trickeling down each object.  This ensures each object will be properly marked.
    As far as your movieClips a factory method is only for the creation of objects, never for the removal.
    You're best bet is to have an object that holds all objects on the stage in a collection.  When you destroy the game. Itterate through this collection and remove them from the stage there.
    This would fit into your engine concept.  There is no reason to use a displayObject for that since its just an object.  Better Yet use a Vector.<DisplayObject> to optimize this.
    Back to your question is this *a* proper way to reset.
    Yeah and No.  The asnwer is based on the memory usage your application eats, and the amount of time to rebuild all objects.  Ideally you should Pool any resources that can be reused versus having to rebuild.
    For example.  If you have a screen that says Game Over.  why would you have to rebuild it on a reset?  There is no information that was changed.   Each clip instantiation takes memory allocated and time.
    Unfortunately without seeing what you have its difficult to say.  But init methods are good and it can be wise to rebuild objects to being again, but as i said it depends.
    Lastly, your line:
    _container.parent.parent.dispatchEvent(new Event(Engine.START_GAME));
    Should not have parent.parent references within.  If you are creating a new Event, at least fall back on eventBubbling to allow the event to travel to the parent.parent.
    You should never target parents like that in a class.  Best practices is to pass in parent.parent as a reference to the class.
    What if you were to add one more layer of parents to the _container.  Then you would have to continue modifying parent.parent.parent.  At least if you bubble the event you dont have to be concerend at all about who listens to it.

  • Incremental Garbage Collector is halting my server for MINUTES at a time.

    I have a Java server which services hundreds (currently 300-700 on average, target of 2000+) of simultaneous client connections, with a staggering number of long lived (but not permanent) objects.
    The docs for incremental garbage collection state: "The incremental garbage collector, which is off by default, will eliminate occasional garbage-collection pauses during program execution." This is NOT true in my case. During peak load, the Server halts occasionally (once an hour or more) and entire MINUTES tick by. Average wait time is 2.5 - 3.5 minutes, the highest I have seen is 4 minutes, 10 seconds. This is entirely unnacceptable.
    The server is on Red Hat Linux 6.2, kernel 2.2.14-5.0, with a gig of RAM. My current command line options are
    java -server -Xincgc -Xms256M -Xmx900M
    And I have just added -verbose:gc to help analyze the gc performance. I have read the gc tuning guide at http://java.sun.com/docs/hotspot/gc/index.html but still feel rather clueless about what is the optimum setup for my particular application.
    I will of course start experimenting, but I was hoping to find a "wise old elf" who might give some useful pointers to accelerate the process, seeing as how the Server is already running in a production capacity, time is critical.

    Are you using a Java application server like Tomcat, Dynamo, WebLogic etc. ?
    In that case consider running several server instances on the machine, with the applicationserver's software load balancer. Find the amount of RAM allocated to the heap per serverinstance where garbage collection runs takes a couple of seconds, and don't allocate more than this to each server. Start as many servers as you have available RAM for.
    This is the approach recommended by application server vendors such as BEA http://edocs.bea.com/wls/docs61/perform/JVMTuning.html and ATG.
    A side benefit of this approach is that in case you get more concurrent users than your computer can handle, you already have the setup for spreading the load over several computers.

  • Optimization of the JVM memory - Garbage Collector

    Hi ,
    Just a question about JVM memory management.
    There is memory limitation of memory usage limitation (1.6M) in JVM.
    Is there any possibility to use "Garbage collector" mechanism to optimize the memory usage?
    Or any suggestions for the JVM memory optimization?
    Thanks a lot!!!

    nicolasmichael wrote:
    Hi,
    the "memory limitation" does not have anything to do with garbage collection, but with the address space your operating system provides. On a 32bit operating system, your virtual address space is limited to <= 4 GB, depending on your operating system (for example 1.something GB on Windows and 3.something GB on Solaris). No.
    Windows 32 bit has a 2 GB application space and can be configured to allow a 3GB space.
    The Sun VM does not allow more because of the way that the executable is linked.
    [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4358809]

  • Possible Bug in Garbage Collector?

    Hello all
    I'm new to these forums but I searched for this problem and couldn't find exactly the same thing - apologies if I missed something.
    I've written an image browser which displays thumbnails, and when you click on a thumbnail it loads the image in a new window. This new window is just a JFrame, with a single JLabel, with an ImageIcon in it, representing the picture. The path name of the picture is passed when this JFrame is created, and the picture is loaded within the JFrame. Therefore, when I close the JFrame, I expect the memory associated with the image to disappear.
    This works. However, when I open a fairly large image (around 1500x1500 pixels), and then close the window, the garbage collector doesn't free the memory. After this, if i continue to open windows with smaller images, they too have the same problem. However, this doesn't happen with smaller images until I open a larger image.
    I think this is a problem with the garbage collector, is this familiar to anyone? Can anyone help? Unfortunately I can't really paste code since this is a university assignment. But you can try it - just load a jframe with a large picture, close it, and as long as the program runs the memory will not be deallocated.
    Any help would be massively appreciated.
    Thanks

    Since you're not willing to post your code it's very hard to comment.
    One question: Are you calling System.gc() after closing these frames? In fact you should probably call it 3 times to make sure the garbage collector takes you seriously. Try this and let us know if you're still showing the leak

Maybe you are looking for

  • Ipod isn't being recognized by my pc or itunes.

    For some reason (probobly something stupid I did) my ipod is telling me to connect to itunes to restore, however when i connect my ipod to my computer itunes doesn't say it has connected and my pc says that it isn't connected in any of the usb ports.

  • How to convert binary data to PDF and attach to the particular po

    our client wants to attach the pdf coming from portal as attachment to that particular PO. From portal the pdf will come in binary format. Find how will we convert that binary data back to pdf and attach to the PO in R/3?

  • Why is the toolbar in safari now black with white text after upgrading ipad 2 to ios7?

    My (retired) mum downloaded ios7 onto her ipad 2 yesterday but is now complaining that when she launchez Safari and uses google, the toolbar at the top of the screen is black with white text. She remembers something popping up during upgrade in the l

  • How does photoshop position fonts in paragraph text boxes?

    I am trying to understand how photoshop places the baseline in a paragraph box. I have a number of custom fonts, when typing in a paragraph text box some of these fonts appear to cross over the bounding box of the paragraph text. I've looked at the f

  • Web Intelligence

    Hi Guru, Any suggestion why web intelligence is taking a lot of time not only for data pulling. 1) When I try to open a new report >>> Starting up the java but will take at least 2 - 45 mins some time. 2) To pull data, it shows estimate time 1s or 24