* How about flash play 8 Garbage Collector working?

Hi, I need to add some Image controls dynamically, yes,the
number of those are unpredictable.
My code to create them like this:
quote:
public function addImg(name:String, x:Number, y:Number):void
var sm1:Image = new Image();
sm1.source = "imgs/down_medium.gif";
sm1.name = name;
sm1.x = x;
sm1.y = y;
this.addChild(sm1);
Then, it appeared in my application. if I add numbers of
Image in my stage, they eat my memory crazily.
so I want to kill some Image which is not in use, but I
crashed.
An Image named "img4kill" in stage, it's index in
this.getChildren() is4, and it holds a image which size is about
230K.
I tried to kill it like this:
quote:
this.removeChildAt(4);
yes, it's remove from the stage in faith, but I watched the
memory that the browser using, before and after killing it.
I found the memory it takes is not released.
How can I kill it from both the stage and memory ? I tried
the global function "delete" ,but failed too.
I know that flash play 8.5 and later use a powerfull
GC(garbage collector), but in the sample above, it dose't work for
me.
who can save me from this mud layer?any ideas?
thanks a lot .
(sorry about my ugly english)
[email protected]

Don't worry, the garbage collector will work very well in this case (and in every other case too :) ). It will only collect an object when no more references are pointing to it. Your array still holds a reference to all the items it contains (unless you explicitly do array[index] = null).
There are only three ways that I know of to destroy a reference to an Object: 1). Set the reference to null 2). Let the reference fall out of scope 3) reassign the reference to another object
The garbage collector will also be able to collect objects that have a cyclical references as long as none of the objects in the cycle are reachable.
It pays to understand the ins and outs of garbage collection and memory management in the VM. Knowing that will let you know, for example, that allocating an Object in Java is a very cheap operation (while it is pretty expensive in C/C++).
Check http://www.ibm.com/developerworks/java/library/j-jtp10283/ and http://www.ibm.com/developerworks/java/library/j-jtp11253/ and for more details about the GC
Also don't worry about the performance impact of setters and getters, either the javac compiler or the Virtual Machines Just In Time Compiler will inline those small methods.
In short don't worry about such low level performance problems and concentrate on your coding style and algorithms. The Hotspot JVM is an amazingly efficient piece of software. It also include a lot of optimizations that work very well in optimizing "standard" code. The more normally you code, the faster your program will be, so don't try clever optimizations tricks, they probably won't work well in java.
Read the following articles for some discussion about performance in Java:
http://www.ibm.com/developerworks/java/library/j-jtp04223.html
http://www.ibm.com/developerworks/java/library/j-jtp09275.html
http://www.ibm.com/developerworks/java/library/j-jtp01274.html

Similar Messages

  • Flash play installation not work - The exe file deelete automaticly and the process is still running

    Flash play installation not work - The exe file deelete automaticly and the process is still running

    Why i get no answer?

  • How to get the garbage collector to work?

    Hi,
    i have i program where i load an image scale it down and save the scaled version in an array. I do this for a whole directory of images.
    After every image i set the temporary variable for the loaded image = null and call the function System.gc().
    My problem is, that the garbage collector does�nt give the memory of the loaded image free and the used memory of my program grows with every loaded image.
    /* Reads all images from a folder an stores them in an Array of images */
         public static BufferedImage[] readScaledImagesFromFolder(String folder,
                   int maxSize) {
              File dir = new File(folder);     /* Open the Folder */
              String[] children = dir.list();          /* Get the children of the folder */
              if (children == null) {
                 // Either dir does not exist or is not a directory
                  System.out.println("No images in the folder!");
                  return null;
             } else {
                  /* Init array for images */
                  BufferedImage[] images = new BufferedImage[children.length];     
                  int i = 0;
                  int index = 0;
                  BufferedImage temp;
                  String filename, fileending;
                 for (i=0; i<children.length; i++) {
                      // Get filename of file or directory
                     filename = children;
         /* Get the fileending of the file */
         fileending = filename.toLowerCase().substring(filename.length()-4);
         if(fileending.equals(".jpg") || fileending.equals(".bmp")
                   || fileending.equals(".png") || fileending.equals(".gif"))
              /* Read the image */
              temp = util.ImageUtils.loadBufferedImage(folder+"/"+filename);
              /* Scale the image down and save it in an array */
              images[index] = Util.getScaledImage(temp,maxSize);
              index++;          
         temp = null;
         System.gc();
         Mosaic.sourceImageNum = index;
         System.out.println((index+1)+" resized pictures loaded from folder: "+folder);
         return images;     
    How can i get the gargabe collector to work after every iteration?
    I tried to let the Thread.sleep(10) after System.gc() but it does�nt help.
    Thank you every much
    JackNeil

    Hm yes.. i now that System.gc() is only a
    suggestion.
    But i know what my program is doing and that it
    does�nt need the temporary image anymore after i have
    a scaled down version. And the temporay image will become unreachable as soon as reading the next one overwrites your temp variable. Setting the variable to null doesn't have much effect.
    It would be smarter to load the new image over the
    old temporary image and not to expand the heapsize to
    maximum.Then look at the possibitly of loading the next image into the same bufferedimage.

  • Can someone explain how garbage collector works in this program ?

    class Chair {
    static boolean gcrun = false;
    static boolean f = false;
    static int created = 0;
    static int finalized = 0;
    int i;
    Chair() {
    i = ++created;
    if(created == 47)
    System.out.println("Created 47");
    public void finalize() {
    if(!gcrun) {
    // The first time finalize() is called:
    gcrun = true;
    System.out.println(
    "Beginning to finalize after " +
    created + " Chairs have been created");
    if(i == 47) {
    System.out.println(
    "Finalizing Chair #47, " +
    "Setting flag to stop Chair creation");
    f = true;
    finalized++;
    if(finalized >= created)
    System.out.println(
    "All " + finalized + " finalized");
    public class Garbage {
    public static void main(String[] args) {
    // As long as the flag hasn't been set,
    // make Chairs and Strings:
    while(!Chair.f) {
    new Chair();
    new String("To take up space");
    System.out.println(
    "After all Chairs have been created:\n" +
    "total created = " + Chair.created +
    ", total finalized = " + Chair.finalized);
    // Optional arguments force garbage
    // collection & finalization:
    if(args.length > 0) {
    if(args[0].equals("gc") ||
    args[0].equals("all")) {
    System.out.println("gc():");
    System.gc();
    if(args[0].equals("finalize") ||
    args[0].equals("all")) {
    System.out.println("runFinalization():");
    System.runFinalization();
    System.out.println("bye!");
    } ///:~
    This code is From Bruce Eckel's "thinking in Java"
    Here is what I understand and what I don't
    At a certain point during the execution of the while loop (in the method main), the garbage collector kicks in and will call the method finalize() -
    I am at a loss as to what happens afterwards -
    Do the chairs continue to get created (which means the variable i keeps incrementing) and the finalize method keep getting called (which means finalized keeps incrementing) till the system realizes it is really low on memory and starts reclaiming memory ie i now starts decrementing ?
    What I would like to know is the exact flow or execution of the code after the garbage collector starts kicking in ie. what happens to the variables "i" (does it increment and then decrement), "created" (does it keep incrementing ), "finalized" (does it keep incrementing) and when is the if i==47{ } statement within finalize() get executed.
    There is no part of the code where i is being decremented (so I am guessing that it is the garbage collector reclaiming object memory that must be decrementing it).
    I am really confused -unfortunately there's very little in the book that really explains the flow of execution after the garbage collector kicks in and finalize() is called.
    Any help would be greatly appreciated

    Nice example, but Bruce chose some suboptimal names, I think.
    "i" can be thought of as the "ID" of a given Chair (note that it is not static). It is neither incremented nor decremented - it's just assigned from "created". This lets us identify specific chairs (like, say, "Chair #47").
    "created" is a running total of the number of times the Chair constructor has been called.
    "finalized" is a running total of the number of Chairs that have been finalized.
    The process starts creating Chairs as fast as it can. Eventually, memory gets low, and gc() starts collecting Chairs. While that's happening, chairs are still being created in the main Thread. So "created" and "finalized" may both be incrementing at the same time.
    When gc() picks Chair#47, the finalizer code sets a flag that causes new Chairs to stop being created. This causes the program to fall out of the while() loop, and the program spits out its data and exits.
    On my machine, the program created 29,542 chairs before exiting.
    Remember - often, gc() runs only when/if the JVM decides it's running low on memory. Specifics depend on the JVM and the startup options you use - some JVMs are very, very clever about doing incremental garbage-collection these days.
    Does that make more sense?
    Grant
    (PS - it's very, very good that you posted a working code sample. But learn about the \[code\] and \[code\] tags, please - makes your sample WAY easier to read...)

  • How intelligent is the garbage collector?

    Hi all,
    I've got a question about how garbage collection works in an ABAP objects context.
    If there are no more references an object is cleaned up and the memory released. Fine.
    What about an object O1, which in turn creates another object O2. O2 however also contains a refernce to O1.
    When the original process completes, this leaves two objects that reference each other, but with no other contact to the 'outside world'. Is the garbage collector intelligent enough to dump them?
    Any input appreciated,
    Cheers
    Mike

    Hi,
    Thanks for the feedback. I am still not sure - you say 'when the program ends it's part'. This is exactly the point - when the program ends, do the objects remain because they still contain references to each other?
    More detail:
    The references are public instance attributes of both objects (different classes). I would prefer to use functional methods, but am stuck with public attributes which I'm populating in the constructor.
    So a process P declares a local var LV_O1 and does a CREATE OBJECT LV_O1.
    In the constructor of O1, it does a
    CREATE OBJECT me->ATTR_O2 to populate it's attribute with a reference to an instance of O2.
    O2 doesn't need to do a CREATE OBJECT, but assigns a ref to O1 to it's attribute ATTR_O1.
    So now O1 and O2 refer to each other by public attributes:
    O1->ATTR_O2 and O2->ATTR_O1.
    The big question is what happens when process P ends and it's variable LV_O1 ceases to exist?
    In case anyone's wondering about the overall wisdom of the design, they have to be public attributes (used in Workflow) and they have to refer to each other as instantiation may also happen the other way around.
    Cheers
    Mike

  • Air 3.9 will support OSX 10.9. How about Flash Builder?

    Currently, only Java 1.6 is supported in FB 4.7.
    Although most of the features work with Java 7, some, like the iOS packager, don't.
    It would also be nice if several bugs were fixed too.
    Are there any plans for updates to FB 4.7 in the near future (or ever)?

    Update to Apache Flex 4.10 and AIR 3.8, they will work just fine with Java 7.

  • 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.

  • Garbage Collector & references

    Hi there,
    is there any possibility to determine in a class "B" if an instance of class "A" just exists because of a reference in class "B" and is not referenced from elsewhere?
    That is, is there a possibility to determine how many references exist for a certain instance?
    Sincerely
    Karlheinz Toni

    Because I do not really get how the garbage collector works and all the why's and when's memory is freed.
    I am doing a xml/xslt Application beeing rather memory consuming (:(). If I try to work with 3-5 files at once each about 50Mb memory runs out :). So I would like to be able to delete all the objects at once if they are not needed anymore.
    I thought like this:
    1.) you could check every time after you used a object if there are still more than one reference.
    2.) If not you've got the only one => free it
    Just a thought. Can you imagine a better way (if yes what is it? :)
    Thx
    Sincerely
    Karlheinz Toni

  • Redirect garbage collector output to a historical file

    Hello to you all,
    I know how to redirect the garbage collector output to a file with the parameter -Xloggc:<file> but there is a problem: Everytime the jvm is rebooted, that file is reset, deleting all the information generated before.
    I would like the jvm to append the new information to that file instead of deleting the old one.
    Is there anyway to configure the jvm to do that?

    Hi you all again,
    Probably I didn't explain my problem correctly in the previous post.
    I'm using J2SDK 1.4.1_02 on a Windows 2K SP1 platform .
    I've read the JVM documentation and I've learnt a lot about tuning garbage collection but almost nothing about how to solve the problem I have.
    I know how to generate the verbosegc output with the parameter '-verbosegc' and how to redirect it to a file with the parameter '-Xloggc:<file>' but everytime the JMV is restarted the content of that file is deleted.
    Is it possible to append content to that file instead of overwriting it and can anyone give me a clue to do this?
    Thank you in advance.

  • Help understand garbage collector behavour in case..

    Here is the case:
    class B{
    // members and methods
    class A{
    B memberAB;
    // other members and methods
    class C{
    B memberCB;
    public void takeAndKeep_B()
    A objA = new A();
    memberCB = objA.memberAB;
    //some code
    // other members and methods
    After takeAndKeep_B() finishes its job,
    garbage collector will not release
    memory occupied by objA
    (because there is still a reference to it's member memberAB, I think)
    Am I getting it right? Or the reason of memory leak is totaly unrelated to this case and I should look for it in some other place?
    I would appreciate any oppinions so mush.

    Here's how the garbage collector works: it collects any objects that the program cannot access. If an object cannot be accessed, it will be collected by the garbage collector if needed.
    In your code, after takeAndKeep_B() finishes, there are no references to the new A object that the objA reference points to. Thus, the A object can be collected by the garbage collector.
    Look at it this way: if the A class had a member named i that was an int, could your program access the i field of the A object you created after takeAndKeep_B() finishes? No, because the reference objA ceases to exist at the end of the method. Therefore, the object is unreachable and may be collected.
    There is no way for an unreferenced object not to be collected by the garbage collector. Java cannot leak memory in this way.

  • I use chrome on windows. Every time I am on Facebook and I am trying to play a game I get a message that says flash player has stopped working. how do i make it work?

    I use chrome on windows. Every time I am on Facebook and I am trying to play a game I get a message that says flash player has stopped working. How do i make it work?

    Hi juderocks14,
    Please first take a check with the other Players and see if they could play the MP4 file normally. If it can't be played, which means it might be corrupted. You may ask at the Bandicam side, or save the files again.
    If issue insists, take a try with the Troubleshooter (For Windows 7, 8 and 8.1):
    Open the Windows Media Player Settings troubleshooter
    Fix Windows Media Player video, and other media or library issues
    Or you may try to turn Windows Features on or off to reset Windows  Media Player:
    Turn Windows features on or off (Before turn it on again, please remember to reboot first)
    More reference:
    What happens if I turn off Windows Media Player?
    Best regards
    Michael Shao
    TechNet Community Support

  • My adobe Flash wont load after installing the upgrade to firefox 6..how can i get it to work?

    i play the facebook games and i need to have adobe flash for it to work and when i upgraded the firefox to 6 the adobe doesnt download..i ve tried it many times and it wont download..

    Symantec need to update their Firefox add-ons so that they are compatible with Firefox 4. They have indicated that for Norton 360 they plan to release an update to Norton 360 to support Firefox 4 in early May - http://us.norton.com/support/kb/web_view.jsp?wv_type=public_web&docurl=20100720113635EN&ln=en_US
    I do not know about the time scale for updates for other Norton products. Pending the update by Symantec, if you want to use the Norton add-ons you will need to downgrade to Firefox 3.6.
    To downgrade to Firefox 3.6 first uninstall Firefox 4, but do not select the option to "Remove my Firefox personal data". If you select that option it will delete your bookmarks, passwords and other user data.
    You can then install the latest version of Firefox 3.6 available from http://www.mozilla.com/en-US/firefox/all-older.html - it will automatically use your current bookmarks, passwords etc.
    To avoid possible problems with downgrading, I recommend going to your profile folder and deleting the following files if they exist - extensions.cache, extensions.rdf, extensions.ini, extensions.sqlite and localstore.rdf. Deleting these files will force Firefox to rebuild the list of installed extensions, checking their compatibility, and reset toolbar customizations.
    For details of how to find your profile folder see https://support.mozilla.com/kb/Profiles

  • Has anyone been able to contact Adobe to learn why their Flash Player does not work on Mac OS 10.6.8, no matter how many updates you install?  This seems like a big error by Adobe.

    I have thee Mac computers with Mac OS 10.6.8, one of which is a Mac Pro.  No matter how many updates I install from Adobe, their Flash Player does not work on any of these 3 computers.  I don't know how to contact Adobe Systems about this problem, but I think it is their responsibility to make sure that their so-called "universal" software works proplerly on a relatively recent operating system like OS 10.6.8 that is still in widespread use.  When you install the updates, nothing happens -- not even an error message.  What is the point of a universal player that is not universal?  It works fine on my MacBook Pro with OS 9 Mavericks, but it does not work at all -- indeed, has never worked -- on my 3 Macs with OS 10.6.8.  Has anyone contacted Adobe Systems to find out why the Flash Player does not work with OS 10.6.8 and what they plan to do about it?

    Where are you getting Flash from?
    Get the appropriate dmg installer here and then run it.
    http://www.adobe.com/products/flashplayer/distribution3.html
    If it still won't install, do these two things: First uninstall any Flash by going into the second level Hard Drive Library>Internet Plug-ins, and trash the Flash Player.plugin and flashplayer.xpt. Then boot into Safe Boot, Shift at the startup chime (give it much longer than a usual boot) and run the installer while booted in Safe Boot.

  • Embedded flash player is not working... Unable to play the streaming videos... Browser is hanging many times!!

    Hi,
    Pls help me to fix an issue with my playbook browser. The embedded flash player is not working... Unable to play the streaming videos... Browser is hanging many times. Restart done, cleared history etc.. Still doesn't work.
    Any help would be appreciated.
    Thanks.
    Solved!
    Go to Solution.

    Hello ak_kanan, 
    Welcome to the forums. 
    Try doing the following. In the browser swipe down from the top and choose Settings, now choose Content, here where it says Enable Flash change this to Off.  Now try going to the website that was not working (it will not work again this is fine) Once on the page swipe down from the top again and this time enable the Flash setting. Now reload the page and test to see if you have the same issue. 
    Let us know how you make out. 
    -SR
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • Garbage collector don't works.

    Hello people !
    When I restart the weblogic server this do not shows the lastest change that I made. I think the problem is related to the garbage collector and its bean tree.
    Do you known how to solve this?
    Thank you.
    Regards.

    I'm working with WebLogic Server 10.0 and the problem is if I restart the server this don't holds the lastest change that I made, it happens with any type of change (deploy, undeploy, create or delete servers/services, etc).
    I've reviewed the log file and I've found the following error:
    <Jun 2, 2008 6:45:14 PM CDT> <Warning> <Management> <BEA-141269> <The temporary bean tree updateDeploymentContext(Mon Jun 02 10:46:11 CDT 2008) was allocated for an undo, get, or activate operation, but has not been garbage collected.>
    Stopping PointBase server...
    PointBase server stopped.
    Thank you for your attention

Maybe you are looking for