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

Similar Messages

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

  • 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

  • Is it possible to disable the garbage collector?

    I was just wondering if it's possible to disable the garbage collector... Thank you.

    Try running with the -Xnoclassgc parameter.
    http://java.sun.com/developer/JDCTechTips/2004/tt0420.html#2

  • How does the Garbage Collector handle reference-free objects?

    Hi,
    I am interested to know how the GC handle's objects created
    without a reference.
    The reason this has become of interest to me is that I have
    created a "Title" class. The Title class animates each letter of
    Title.text to appear in a cloud of smoke.
    The smoke is a simple particle system class, when a particle
    dies it removes it's associated MovieClip so that eventually all
    MovieClip's have been destroyed.
    Now in the Title class for each letter I do the following
    (psuedo-code):
    for( Title.text.length) {
    CurrentLetter.twAlpha = new Tween( blah, blah, blah); //
    object created
    with a reference
    new Smoke( CurrentLetter.x, CurrentLetter.y); // object
    created
    without a reference
    Although this is technique is not one I would ever have
    thought of in a language that doesn't use a garbage collector it is
    mentioned in the Tween documentation and my class works as
    intended.
    The thing is although it works, it always bothers me when I
    don't know precisely
    why it works!
    If it's working due to the short life span of the class in
    question and thus simply missing the GC's window then this could be
    problematic. If at some point it is still alive when the GC is
    called then my class could be prematurely deleted.
    Maybe a class which has a reference to an "alive" MovieClip
    is immune from GC?
    I Hope someone can shed some light on this topic as the GC is
    something that is thinly documented to say the least!
    :theory
    p.s. first post!

    Hi,
    I would say it would be better use FREE itab at the end of the processing in your code. In the end-of-selection in your code, you can FREE all your itabs that were used in the program. This is one of the good approach of optimizing the memory.
    Regards
    Vimal

  • How to Change the Garbage Collection Algorithm in WLS 9..2

    Hi All
    I am trying to find out the way to configure the GC algorithm in weblogic 9.2 to type bea.Jmapi.GarbageCollector@.
    By default it is showing ‘Nursery, parallel mark, parallel sweep’ . We were trying to change it to generational (two-spaced) with a parallel mark algorithm and a concurrent sweep algorithm or bea.Jmapi.GarbageCollector .
    To change the same I modified the memory argument in commenv.cmd to set MEM_ARGS=-Xms128m -Xmx256m -XXsetGC:genparcon
    Still Garbage Collection Statistics section in web logic console shows the same default value.
    Could anyone tell me if I am missing something?
    thanks in advance

    There is nothing is WebLogic that will define the JVM GC algorithm, that is up to the JVM settings that are normally configured using params in the start scripts.
    If you are using JRockit, you can ask in the forums but the JVM documentation should really be sufficient.
    JRockit
    Same thing for the Sun JVM, there is lots of information out there on how to change the GC algorithm.
    The thing that is nice about JRockit is that you can use the Mission Control tooling to take recordings, look at the GC's and make adjustments easily. Sun has some tooling as well with jvmstat (and visualgc), but I'm not as familiar with it.
    http://java.sun.com/performance/jvmstat/
    Both of those tools would be much preferred to printing the GC info to a file and trying to parse it in my opinion.

  • Using Java Program Can we know when the garbage Collector is called?

    Hi all,
    Can we create java program to find the time (Garbage collection time)
    I want to know the time limit of Garbage collection? How did the JVm knows the object is not reachable ?
    Pls help me
    regards,
    namanc

    Hi all,
    Can we create java program to find the time (Garbage
    collection time)Add "-verbose:gc" to your java command line.
    I want to know the time limit of Garbage collection?Can you be more specific?
    How did the JVm knows the object is not reachable ?See http://java.sun.com/docs/hotspot/gc1.4.2/.

  • Helping out the Garbage Collector

    Hey, need a bit of advice:
    I'm working on an app which is doing a particular task every so often. Left to its own devices, the memory size of the application quickly baloons up to around 300,000k before settling in. However, if I start each iterator with a System.gc(), the memory consumption is a more manageable 80,000k. However, running gc so much really sucks down the cpu and causes everything to go slowly. Anybody have any suggestions about how I can help java clean up better?
    Thanks

    maybe GC is convienent, but someitmes I like to be a control freak.
    anyway, for the benefit of the community... It appears that cleaning up a StringBuilding is easier than cleaning up a string. i.e.
    StringBuilder results = new StringBuilder();
                           while ((line = reader.readLine()) != null) {
                                if (line.equals(commEscape)) {
                                     parseResults(results.toString(), node);
                                     return;
                                results.append(line);
                                results.append("\n");
                           }cleans up much nicer (i.e. doesn't baloon up to 300M) than
    String results = ""
                           while ((line = reader.readLine()) != null) {
                                if (line.equals(commEscape)) {
                                     parseResults(results.toString(), node);
                                     return;
                                    results += line + "\n";
                           }at least in my application :)
    I wonder why that is?

  • Problem with the garbage collector

    Well, I have a problem, and it's quite a big deal.
    I don't understand why the java BC refuses to free the memory.
    I have made a VERY LITTLE example, so that everybody will see what the problem is made with.
    a frame with 2 buttons. the first one make another frame appears, which contains a quite big Swing component. The other is here in order to try to free the memory of this frame.
    Here are the 2 classes :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class FirstClass extends JFrame{
    private JButton jButton1 = new JButton("free memory");
    private JButton jButton2 = new JButton("load frame");
    private MyFrameColor frame;
    public FirstClass() {
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton1_mouseClicked(e);
    jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton2_mouseClicked(e);
    this.getContentPane().add(jButton1, BorderLayout.NORTH);
    this.getContentPane().add(jButton2, BorderLayout.SOUTH);
    this.show();
    public static void main(String[] args)
    new FirstClass();
    import javax.swing.*;
    import java.awt.*;
    public class MyFrameColor extends JFrame {
    JColorChooser jColorChooser1 = new JColorChooser();
    public MyFrameColor() {
    this.getContentPane().add(jColorChooser1, BorderLayout.CENTER);
    }

    Some more info on garbage collection:
    http://www.javaworld.com/javaworld/jw-12-2001/jw-1207-java101.html?
    http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/

  • I wonder how to delete the garbage files in my iPhone

    After uninstalling an APP there must be junk files about this APP still exist,and how to delete these junk to save more space.
    my iPhone did not jailbreak.I used an APP called iClear to clean my device but it just wipe a little.Any suggestion?

    fter uninstalling an APP there must be junk files about this APP still exist,
    What makes you think that?

  • Can we explicitly stop the garbage Collector(which is running in background

    Hi all,
    we can clean up some memmory using System.gc() or freeMemory(). But my query is that we have to stop the gc which is running at the background in the JVM in java.
    I would request u all, to help me out in solving my query.
    Thanks & Regards,
    Mohan

    Calling System.gc() from the code is not good development practice. You shouldn't have to worry about the GC.
    Are you experiencing problems? Which ones?
    -Alexis

  • How intelligent are the compilers?

    I've got some lines of code like this:    public Connection getConnection() throws SQLException
            if ((iv_connection == null) || (iv_connection.isClosed()))  // !!!!!!!!
                iv_connection = connect(iv_DBUser, iv_DBPasswort, iv_DBName);
                iv_connection.setAutoCommit(false);
            return iv_connection;
        }The problem is the if-clause. If the property iv_connection is null the rest of the clause does not have to be tested. But if it would be tested I would get a NullPointerException. The Webgain (Visual Cafe) compiler does a good job and the second part of the if-clause is not tested. But do all the other compilers do this too? I would like to be sure if the code is ok.
    koem

    You are right. All compilers should not evaluate the 2nd part of the statement if the first part is false. This is standard logic for an 'or' statement/gate. The compiler only need one false to evaluate false, it gets it on the first expression.
    I would not expect any compiler to reach the 2nd statement in the case of 1st statement bieng false.
    unless written by a student/consultant/etc. lol

  • How intelligent is the Workbench Request?

    Hi,
    I created an ABAP program and the Workbench Request was created too. I want to know before Releasing the Request if I go and modify the ABAP program may be after Few Day’s will that modification get added to the existing Request which was created at the time ABAP program creation?
    Thanks,
    Kishan

    YA.. Until u release the request once created for a report(or any object) all the changes will reside in that request only. If u delete the existing request explicitly then a new request should be created again.
    If ur doubt is cleared pl close the thread.
    Regards,
    Pradhiba

  • How to find the STATISTICS COLLECTOR infomations

    Hi experts
    where i can find these informations,
    Average dialog steps
    For week & For a day
    Peak dialog steps on a day
    Average dialog response time
    For week & For a day
    Peak dialog response time
    Average memory utilization
    For week & For a day
    Peak memory utilization
    For week & For a day
    Average database response time,
    For week & For a day
    Peak database response time,
    For week & For a day
    Average CPU load
    For week & For a day
    Peak CPU load
    Average no of users logged into the system for a week, on a day during the peak hour traffic
    Please help me to find
    Thanks & Regards
    Venkat

    Hello Venkatesan,
    If you are asking about statistics the best transactions would be:
    ST03N- This transaction is a workload analysis monitor. Here you can switch to expert mode and select detailed analysis menu.
    There is an option to select for the current day. If you want to have data for a week, select the analysis type (example: detailed analysis) and give the start date and any other filters you want.
    The system will then display, avg dialog response time, DB time, CPU time etc.
    For memory usage statistics, there is an option in the left Pane called Memory usage statistics. Select this.
    Where as ST03N gives an aggregated statistical view, another transaction STAD gives and unaggregated view i.e it display each execution of transaction independently.
    One more thing, for the JAVA stack, the statistical records will be displayed in ST03G (Global workload analysis- aggregated) and STATTRACE (unaggregated).
    For CPU peak loads i would suggest the transaction ST06 and for database the transaction ST04.
    For a complete picture of the buffers and their utilization, the transaction would be ST02
    Hope this helps
    Regards,
    Prashant

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

Maybe you are looking for

  • ICloud documents not showing up in iCloud

    Using Pages I have a number of documents that just don't show up on any of my iCloud devices (including iCloud from my Mac, when I click Open and go to iCloud they aren't there). I have tried duplicating the files and saving them to iCloud but they s

  • Multi-touch development contest to win 30" LCD Multi-touch screen

    Hello Adobe Users, In an effort to raise awareness of multi-touch interaction, and to encourage the development of new multi-touch software,  Demand Evolution, a new open-source driven multi-touch hardware company, is announcing its first multi-touch

  • Bare Metal Restore of AD

    I have inherited a domain setup at my new company and unfortunately a few of the 2008 R2 domain controllers only have 1 hard drive installed so if that drive fails the server is gone.  I am going to purchase a second hard drive so I can get this DC o

  • Improve a query's performance

    Hello I need to make a query that will return a value when there are rows that meet a certain condition and another value when there are rows that meet another condition, the most simple way I thought of was using two queries like that: +1. select co

  • Opening RAW from G15 in Elements 10

    I am not able to open RAW files form my Canon G15.  I checked my program and it does have the latest camera raw plug-in.  Any suggestions?