Do you think JOptionPane dialogs force garbage collection afterwards?

I ask because I've made a nested static class to implement my own file selection tool; the problem is that each time I call it the old JPanel is being recalled and so the components get re-added to it each time it's called, resulting in n versions of each file for every n times you open it.
I'm running myDialog.dispose() upon exiting, so is my only option now manual garbage collection? How could I force it to be garbage collected? Because System.gc() seems to have no effect.

Strictly speaking there is no way to force garbage collection, so, no, JOptionPane will not be doing it.
You almost certainly have a leak in your code. Post it and we may be able to help.

Similar Messages

  • Memory leak in java / forcing garbage collection for unused resource?

    Is there any possibility in big programs if not designed properly for leakage of memory?
    If say i forget to force garbage collection of unused resouces what will happen?
    Even if i am forcing garbage collection how much assurity can be given to do so?
    I need answers w.r.t typical programming examples if someone can provide i will be happy.
    Or any useful link.
    Thanks
    Vijendra

    Memory leaks are usually much related with C/C++ programming since in that language you have direct access to memory using pointers.
    Now, in Java you do not have access to pointers, however you could still tie up your objects in a way that the garbage collection can not remove them.
    Basically, the grabage collection will search all the object implementation, and see if they are referenced or not. If not it will free that memory. However if you, somehow in you code allow a reference to your object then the garbage collection will not displose of that object.
    An example I can think of is when developing web applications. For example storing objects in the session will mean that you will have a reference to the object from the session, therefore the garbage collection will not free up the meomry taken by those objects untill the session has expired.
    That is how I know it... at least that is how they tought it to me!
    regards,
    sim085

  • Force Garbage Collection through scripting

    Hi ,
    I am using weblogic server 8.1.5 on windows 2003 server.
    can we do force garbage collection through a script? If so can i have a sample script for the same?
    OS:windows 2003 server
    thanks in advance.
    Madan Mohan

    And the key here is "any length of time". I used to have WLDF notification on for all errors in the log file, but I specifically disabled it for the "almost out of memory" error, because it happened constantly, even when we didn't really have a memory problem. It's a little harder to determine the "any length of time" constraint. I'm not aware of an interface to "gc()" through WLST, which would be the most practical way to do this.
    I think it's possible the "shape" of your free/used memory patterns would change if you changed your GC algorithm. If you're currently using a "stop the world" collector, the free memory percentage will probably decrease almost to zero before it collects. However, if you use a generational collector, it's possible in normal operation that you won't get down so close to zero before it collects. In that case, the "almost out of memory" error might be more meaningful.

  • Force Garbage collection externally....

    hi!
    I am new to java.is it possible to the force Garbage collection externally?
    can i achieve it by giving the command "System.gc();".pls give me idea...
    Thanx
    Rgds,

    You can't force a full GC as far as I know. gc() might force a GC of the youngest generation.
    Why do you think you need to force it?

  • Applescript: force garbage collection?

    Hello
    I am trying to call applescript functions (from my cocoa application - using NSAppleScript's -executeAndReturnError), to automate some operations in Microsoft Word.
    The problem is that after every Applescript call, the Word operates slower and slower (and i guess finally it won't respond at all). I am calling operations, like "set myvar to all words of current document whose [some conditional]" or "set myvar to all fields of current document whose [some conditional]" (which are memory consuming - on each call Word enumerates all the words of a long document, searches there some matches, etc), and i think that after each call of NSAppleScript's -executeAndReturnError, Word doesn't clean its previous "results", which slows it down with every next call. I wanted to try to do an explicit call of Applescript's garbage collector after each -executeAndReturnError from my Cocoa app, maybe that could eliminate the problem i have.
    But i didn't find any info on how to do that. Java, ActionScript - both have System.gc() functions (that launch Garbage collection if it's needed right here and right now). If theres no way to force garbage collecting in AppleScript, maybe someone knows "implicit ways", when AppleScript engine calls it? Like the next iteration of a loop, or some other conditions? Or some timespan, after passing which the GC is called?
    What could cause that slowness of Mac:Word? Is it a mistake of Microsoft, or am i forgetting to do something? If someone could advice readings about how applications usually implement Applescript interface "from the inside" (and who is responsible for cleaning the results of each call), i'd be very thankful.
    Thanks for any advice!
    George

    If you really want to see the results you should also run the finalizer
    thread on the newly garbage collected objects. It might take up to 2 GC
    cycles for the memory to be actually free for new allocation at least on
    the Sun JVMs. Maybe the new types of garbage collectors do it better or
    more optimized but anyway, the GC would first mark the objects and only
    then the finalizer will run to call the finalize method. Then next GC
    will free the memory of the finalized objects.
    HTH,
    Dejan
    Dinesh wrote:
    Hi Slava Imeshev,
    Thanks for immediate response. I agree JVM will do GC at specific interval. But,
    I have found that , there is some difference in both of them. If you invoke "Force
    Garbage Collection" explicitly, the graph will show the heap memory usage to baseline.
    Where in, if you perform System.gc(). It won't make much difference.
    Thus why, I want to know what is the code behind the "Force Garbage Collection"
    button.
    Thanks,
    -Dinesh.
    "Slava Imeshev" <[email protected]> wrote:
    "Dinesh" <[email protected]> wrote in message news:406a8df4$[email protected]..
    How can i schedule "Force Garbage Collection" to be done at every
    week or daily?.
    Can i automate this process instead of manually invoking the button?
    GC is already done by JVM automatically.
    Why would you want to "schedule" it?
    Regards,
    Slava Imeshev

  • Why can we force Garbage Collection

    Hello,
    Why can we force garbage collection since we have AUTOMATIC garbage collection?

    If you don't call dispose on the Window, it may keep a
    GUI thread running in the background. Since this
    thread is still running and accesible from the root,
    it will hold onto the Window. You should always call
    dipose() on Windows you want to be completely removed.I know I should that's why a mentioned it! But is it correct that I should have to? Nowhere in the documentation does it say so. The fundamental principle is you let go of all object references and eventually the object will be removed by the GC. In this case this important principle is broken.
    At least a clear WARNING should be stated. Window (and all its subclasses) break an important principle of Java. If you don't call dispose your program will leak memory !!!

  • Force Garbage Collection

    Before I load a new level, should I force garbage collection on the old level? And if so, how?

    Just remember that the method suggest the garbage collector to run, not forcing it..
    If you have a lot of objects created that are later available for garbage collecting, you could try to reuse the objects instead of creating new ones (if garbage collection is really a problem for you).

  • Howto Force Garbage Collection manually in Oracle Application Server

    Hi,
    I have a Oracle SOA suite installed on Oracle 10g Application Server. The heap memory for the SOA oc4j container is 2G with a permgen space of 256M. But it looks like there is some memory leak somewhere and the Heap area is getting filled frequently and this causes an *[libopmnoc4j] OC4J ping attempt timed out* and as a result of this the SOA oc4j container gets restarted automatically.
    Is there any means by which we can force a Garbage Collection manually so that this automatic restart does not happen.
    Kindly let me know if it is possible to trigger a Garbage Collection manually in Oracle Application Server.
    Thanks,
    Vijay.

    We had a similar situation where the oc4j instance will throw OutOfMemoryException and opmn will restart a new instance every 10-12 hours. The JDBC 10.2.0.3 driver has a memory leak in the XA Resource classes. There is a fix available in metalink.

  • Will system.gc() force garbage collection?

    what impact will the method system.gc() have if i call it in one of the user methods.

    If you use Sun's HotSpot 1.5.0 JVM (or later) with the -XX:+UseConcurrentMarkSweepGC (low-latency) garbage collector, you can use the additional flag -XX:+ExplicitGCInvokesConcurrent to have calls to System.gc() initiate a concurrent collection, rather than cause a stop-the-world compacting collection, which calling System.gc() usually does. Most people who run the low-latency collector are trying to avoid the pauses caused by compacting collections.
    If you have some annoying third-party library that calls System.gc() and that upsets your application's performance, you can use the additional flag -XX:+DisableExplicitGC to make calls to System.gc() into no-ops. That works with whatever collector you are using.

  • Can I force full garbage collection?

    Hi, my program is memory bound , as users load more files more memory is required , if the user decides to load a very large number of files they will eventually run out of memory. So I am trying to detect when there is less 15% of heap memory left, then force garbage collection and if it cant free up more than 15% of the heap I will stop the user from loading any more files. But the problem is though I call System.gc() to try and force a full garbage collect it rarely
    retrieve enough memory to get below the 15% limit. But using the Yourkit Profiler I can select the Force GarbageCollection option and this always manages to free up more memory to get the figure under the 15% limit. in support of this I found that sometimes my program stop me loading more files when there is still quite a bit available.
    So my questions are.
    1. I know System.gc() is only hint to garbage collect, but the docs imply it only replys after the garbage collection (if any) has been done, is this right or do I have to wait.
    2. Is there any way to Force complete Garbage Collectionas profiler appears to do.
    3. is there a VM option I could set instead to force the JVM to completely garbage collect at say 83% so that if I then polled that 85% of heap was being used I would know that it really was, and I wouldnt need to bother trying to garbage collect further. (Im using Suns 1.6. JVM on Windows and Linux, and Apples 1.5 or 1.6 JVM on Macs)
    public static void checkMemoryWhilstLoadingFiles() throws LowMemoryException
            MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
            //No max defined future proofing
            if(mu.getMax()==-1)
                return;
            if (mu.getUsed() > (mu.getMax()  *  0.85f))
                MainWindow.logger.warning("Memory low:" + mu);
                System.gc();
                MainWindow.logger.warning("Memory low gc1:" + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
                System.gc();
                MainWindow.logger.warning("Memory low gc2:" + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
                System.gc();
                MainWindow.logger.warning("Memory low gc3:" + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
                mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
                if (mu.getUsed()  > (mu.getMax()  *  0.85f))
                    MainWindow.logger.severe("Memory too low:" + mu);
                    throw new LowMemoryException("Running out of memory:"+mu.getUsed());
                else
                     MainWindow.logger.warning("Memory usage reduced to:" + mu);   
        }thanks for any help Paul
    Edited by: paultaylor on 27-Jun-2008 11:10

    On all of the current Sun HotSpot JVM's, calling System.gc() will cause a full compacting collection. Unless you have -XX:+DisableExplicitGC on your command line, in which case the call is a noop. Or if you are running the mostly-concurrent collector (-XX:+UseConcMarkSweepGC) and have the -XX:+ExplicitGCInvokesConcurrent flag on your command line, in which case calling System.gc() will start a concurrent collection (and the calling thread will block until the cycle is finished).
    But calling System.gc() isn't enough to recover all the space that might be recovered. For example, System.gc() will identify objects that are unreferenced but need to have their finalize() methods called before their space becomes available again. So one call to System.gc() won't recover their space. Those finalize() methods need some cycles to run in, so back-to-back (or back-to-back-to-back :-) calls to System.gc() won't help. If you use a lot of finalize() methods, you should leave a lot of time for the finalize() methods to run between the calls to System.gc(). (Better would be to convert your code to use WeakReferences and run your own reference processing queues, and then you could tell when you were done processing references. But that's real work.) Some people try calling System.runFinalization() and wait for that to return, but that has at least two failure modes (details left to the reader).
    In addition, there are details like: if there is still 15% of the heap free, then we won't aggressively clear SoftReferences when you call System.gc(). We might if you waited until the heap was full and we collected it on our own, since we know how much free space there will be after a collection at the point where we are choosing which SoftReferences to clear, and use that to decide how aggressively to clear SoftReferences.
    There is no method to force the collector to do a compacting collection at, say 85% full. There is an option to have the mostly-concurrent collector start a collection cycle that way. But there's no way to find out if a collection cycle is running.
    You are skating on the edge of the qualities of service offered by the different collectors in the various JVM's available. That weakens your ability to "write once, run anywhere".

  • Cache voluntary garbage collection called

    We have installed Oracle Web Cache 2.0.0.4.0 on Windows 2000. We setup the Maximum cache size parameter to 1000Mb, but, when we try to caching a web using WGET, Oracle Web Cache return a "cache voluntary garbage collection called" in the file of log: "event_log".
    What is the problem?

    The message you're seeing in the event log isn't necessarily a problem. The cache has a voluntary garbage collection mechanism that "wakes up" periodically, checks to see if the system is sufficiently idle, and begins to clear out garbage (invalidated/expired) files. This is different from "forced garbage collection", which occurs when the cache nears its maximum size.
    Are you able to cache content? Are you seeing responses served out of the cache?
    I would strongly advise you to upgrade to release 9.0.2, available for download on OTN. There is also a migration tool there for moving from 2.0.0.x to 9.0.2.x. After you've migrated, you can optionally apply the 9.0.2.1 patch set, available on Metalink.

  • A possibility to prevent garbage collection?

    inspired by the topic "Why can we force Garbage Collection" i asked myself if it is possible to explicitly prevent the automatic garbage collection of the VM.
    regards
    ~elchaschab

    hmm.. you didn't understand my question.
    it's not about prevent the VM from freeing unused
    objects, it's about preventing it doing it at the
    wrong moment (e.g. a highly interactive part of code).No. But Sun's current GC works in smallish increments to reduce the impact. In extremis, you'd have to look at the realtime java project.
    As for preventing objects from being reclaimed, even storing a reference to the object isn't sufficient. You have to provide code that convinces the optimiser that the object will actually be used again in a way that the optimise can't conclude is functionally null. Putting it in a list that will be traversed by an on-exit handler, which in turn will pass it to a native method would do it. Not sure whether anything else is sufficient.
    Now throw in Reference objects and finalizers, and things really get exciting :(
    Sylvia.

  • Froce garbage collection

    Is there any other way to force garbage collection besides
    system.gc()
    Runtime.ExcuteFinalization()
    I know thoes still does not guranteen garbage collection.
    How to improve performace to maximize the possibility for garbage collection?
    Thanks

    How to improve performace to maximize the possibility
    for garbage collection?As soon as you are done using the object references, get them out of scope :) That would help. Calling System.gc() wouldn't.

  • Swing & Garbage Collection

    If the EventQueue is very active does that starve the garbage collection? Here is the scenario:
    Lets say I have a JFrame that listens for a specific keyboard event. In processing that event a heavy weight JComponent is created and displayed within that frame. If the user, in rapid succession, triggers those key events, and continues to, the allocated memory increases dramatically unitl an out of memory exception occurs.
    Does anyone know if alot of processing is occuring on the Swing EventQueue if that might starve garbage collection?
    Thanks
    Scott

    Firstly, if garbage collection is happening later then you're probably ok. You can't force garbage collection - as long as it gets cleared later the only problem you should ever have is the possibility of some piece of code being slowed slightly by the garbage collector kicking in.
    Secondly, it's best to flush() images before the references are lost. Note that you lose an image reference during your getScaledInstance() line, so you should use a temporary variable to allow you to flush.
    It's been a long time since I looked at Jimi, might you need to perform some sort of cleanup on that canvas before nulling it? I'm also not sure why you're using File and JimiCanvas objects when you can just use the ImageIcon(String) constructor to load the image in one line and reduce the risk of introducing errors.

  • Oracle JVM Garbage Collection not executing

    I am experiencing a problem with garbage collection when running a java stored procedure in an 9.2.0.3.0 Oracle database running on a Windows 2k computer.
    I have created a simple java class that represents a tree structure. Each instance of the class has a reference to it's parent and a Vecotor of all it's children. Each instance also has a Vector to hold name value pairs. I ran a program that creates 30 instances with 50 children each for a total of 1500 instances. Each instance has 30 properties(name value pairs).
    By using the debugger in JDeveloper and breakpoints I can watch the javaw.exe process's use of RAM.
    Start up: 6,788mb
    After creation of 1500 instances: 17,720
    After releasing all objects and calling System.gc(): 7,156
    I deploy the package to my Oracle database and perform the exact same routine using breakpoints and test procedures in plsql Developer. Using the breakpoints and watching the oracle.exe process's use of RAM I see:
    Start up: 81,116mb
    After creation of 1500 instances: 94,952
    After releasing all objects and calling System.gc(): 95,036
    When run in Oracle the resources are not released. Is there somthing special that needs to be called to get the garbage collector to do it's job when running in an Oracle database?
    Execution Instructions and source:
    run app.main from jdeveloper and app.main2 as a plsql stored procedure. I have included my test procedure at the end and the plsql stored procedure package declarations. I used debuggers and breakpoints to watch the process, there is probably a way to do this by outputting the current memory being used by I didn't know how. If you use debuggers and breakpoints then when running in JDeveloper put your breakpoints on the 3 assignments of breakpointVar in SimpleClass.main(...). When running the stored procedure test block put them on the 3 assignments of breakpoint_var in there.
    package mypackage2;
    public class app {
    private static SimpleClass topObject;
    public static void main(String[] args) {
    int breakpointVar;
    breakpointVar = 0;
    main2(30, 50);
    breakpointVar = 1;
    release();
    breakpointVar = 2;
    public static void main2(int numParents, int numChildren){
    SimpleClass temp;
    SimpleClass child;
    topObject = new SimpleClass();
    for(int i = 0; i < numParents; i ++){
    temp = new SimpleClass();
    addProperties(temp, 30);
    topObject.addChild(temp);
    for(int j = 0; j < numChildren; j++){
    child = new SimpleClass();
    addProperties(child, 30);
    temp.addChild(child);
    public static void release(){
    topObject.releaseAllDecendents();
    topObject.release();
    System.gc();
    private static void addProperties(SimpleClass toAddTo, int numProps){
    cimxProperty toAdd;
    for(int i = 0; i < numProps; i ++){
    toAdd = new cimxProperty("prop "+i,"value "+i);
    toAddTo.addProperty(toAdd);
    package mypackage2;
    import java.util.Vector;
    public class SimpleClass {
    private Vector _children;
    private Vector _props;
    private SimpleClass _parent;
    public SimpleClass() {
    _children = new Vector(10, 5);
    _props = new Vector(10, 5);
    _parent = null;
    public void addChild(SimpleClass toAdd) {
    toAdd._parent = this;
    _children.add(toAdd);
    public SimpleClass getChild(int index){
    return (SimpleClass)_children.get(index);
    public void addProperty(cimxProperty toAdd){
    _props.add(toAdd);
    public cimxProperty getProperty(int index) {
    return (cimxProperty)_props.get(index);
    public void releaseAllDecendents()
    SimpleClass temp;
    //remove all references to the the parent object from the children.
    for(int i = 0; i < _children.size(); i ++)
    temp = (SimpleClass)this._children.get(i);
    temp.releaseAllDecendents();
    temp._parent = null;
    temp._props.clear();
    temp._children.clear();
    temp = null;
    this._children.clear();
    public void release() {
    this._parent = null;
    this._children.clear();
    this._props.clear();
    package mypackage2;
    public class cimxProperty
    private static String _dateFormat = "MM/DD/YYYY HH:MI:SS";
    private String name;
    private String value;
    private String dataType;
    public cimxProperty()
    name = "";
    value = "";
    dataType = "";
    public cimxProperty(String Name, String Value)
    name = Name;
    value = Value;
    dataType = "UNKNOWN";
    public cimxProperty(String Name, String Value, String DataType)
    name = Name;
    value = Value;
    dataType = DataType;
    public String toString()
    return name + "["+dataType + "]: " + value;
    public void setName(String name)
    this.name = name;
    public String getName()
    return name;
    public void setValue(String value)
    this.value = value;
    public String getValue()
    return value;
    public void setDataType(String DataType)
    this.dataType = DataType;
    public String getDataType()
    return dataType;
    CREATE OR REPLACE PACKAGE JAVA_MEMORY_TEST AUTHID CURRENT_USER AS PROCEDURE release; PROCEDURE main2(p_num_parents IN NUMBER, p_num_children IN NUMBER); END JAVA_MEMORY_TEST;
    CREATE OR REPLACE PACKAGE BODY JAVA_MEMORY_TEST AS PROCEDURE release AS LANGUAGE JAVA NAME 'mypackage2.app.release()'; PROCEDURE main2(p_num_parents IN NUMBER, p_num_children IN NUMBER) AS LANGUAGE JAVA NAME 'mypackage2.app.main2(int, int)'; END JAVA_MEMORY_TEST;
    declare
    number breakpoint_var
    begin
    -- Call the procedure
    breakpoint_var := 0;
    java_memory_test.main2(30, 50);
    breakpoint_var := 1;
    java_memory_test.release();
    breakpoint_var := 2;
    end;

    When run in Oracle the resources are not released. Is there somthing special that needs to
    be called to get the garbage collector to do it's job when running in an Oracle database?Curious - I was always under the impression that you can not force garbage collection. All you could do was request it, and the JVM was free to do that when it was "good 'n ready", usually in a separate thread.
    I gather this from the API docs for system.gc() where it says "Calling this method suggests that the Java virtual machine expend effort ..." and the word "suggests" imlies that it is not required to run.

Maybe you are looking for

  • Possible to replace 30gig HD with a 60gig HD?

    If I buy a replacement 60gig hard drive on ebay or whatnot, would it be possible to replace it with the hard drive in my 30 gig ipod? Would this be compatible?

  • Financial reporting studio - Invalid Picture

    Hi; I am trying to add a new logo into one of our reports (Oracle Hyperion Financial reporting studio, Fusion Edition), however after inserting the new image I get the following error message " Invalid Picture". I have changed the format of the pictu

  • GL: Import Journal only accept those non-functional currency

    Hi, I have tried to run import journal using Oracle General Ledger. However, I found that there is always an error 'EC08 - Invalid currency code' when the records contains functional currency code, e.g. HKD. For all other currencies, like JPY, i.e. n

  • Best processor for Photoshop

    I'm buying a new system running Windows 7, 64-bit. Does CS3 take advantage of the triple memory channel on the i7-9xx series? The turbo on the i7-8xx is apparently much better, but it's only dual channel memory. I am generally processing dng files th

  • PS elements trial download ?

    I tried to download PSE 10 last night and it said it would take 6 hrs.  This morning I have the Adobe Assistant icon on my desktop but no program.  I downloaded to my C drive in a separate file for Adobe.  I see in there the PDE 10 installer and i ha