Memory leaks of KeepAliveCache in special circumstances

Hi,
    In a production environment encountered a memory leak problem after running over 200 days, and i found KeepAliveCache.java will produce memory leaks if it create native thread failed.
    I think if keepAliveTimer.start() failed, java.lang.Thread object was not destory and can not collection by GC.
java.security.AccessController.doPrivileged(
   new java.security.PrivilegedAction<Void>() {
   public Void run() {
      // We want to create the Keep-Alive-Timer in the
       // system threadgroup
       ThreadGroup grp = Thread.currentThread().getThreadGroup();
       ThreadGroup parent = null;
       while ((parent = grp.getParent()) != null) {
           grp = parent;
       keepAliveTimer = new Thread(grp, cache, "Keep-Alive-Timer");
       keepAliveTimer.setDaemon(true);
       keepAliveTimer.setPriority(Thread.MAX_PRIORITY - 2);
       // Set the context class loader to null in order to avoid
       // keeping a strong reference to an application classloader.
       keepAliveTimer.setContextClassLoader(null);
       keepAliveTimer.start();
       return null;
we found the top 10 objects used memory are as follows
num     #instances         #bytes  class name
   1:       2287176      256163712  java.lang.Thread
   2:       3200649      197768504  [C
   3:       2378720      190314944  [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;
   4:        182033       90707352  [Ljava.lang.Object;
   5:       2382405       76236960  java.lang.ThreadLocal$ThreadLocalMap$Entry
   6:       2378720       57089280  java.lang.ThreadLocal$ThreadLocalMap
   7:       2286842       54884208  java.security.AccessControlContext
   8:        212233       28031904  <constMethodKlass>
   9:        902205       21652920  java.lang.String
  10:       2424218       19393744  java.lang.Object
But there are not so many threads in the thread dump, and we found many error log as following:
07:43:21.748  ERROR  WebContainerAdvertiserThread  ?  **.webcontainer.advertiser.startup.WebContainerAdvertiserThread  advertise  WebContainerAdvertiserThread.java  105 
Exception Occured when advertising WebContainer Details
java.lang.OutOfMemoryError: unable to create new native thread
  at java.lang.Thread.start0(Native Method)
  at java.lang.Thread.start(Thread.java:640)
  at sun.net.www.http.KeepAliveCache$1.run(KeepAliveCache.java:89)
  at java.security.AccessController.doPrivileged(Native Method)
  at sun.net.www.http.KeepAliveCache.put(KeepAliveCache.java:75)
  at sun.net.www.http.HttpClient.putInKeepAliveCache(HttpClient.java:370)
  at sun.net.www.http.HttpClient.finished(HttpClient.java:358)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1393)
  at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
SUSE Linux Enterprise Server 10.3
Regards

Hi there..
I'll just answer you what I know..
This code below is when you write your JNI using C++
// this is how to access a java String   
const char *strZ =  env->GetStringUTFChars(
rs( xlzMessage, 0 );
// this is how to let go of java String     
env->ReleaseStringUTFChars( xlzMessage, strZ);     This code below is used when you write your JNI using C
   (*env)->ReleaseStringUTFChars(env, <jstring>,
<char*>);Is this the same as what I have above? If not, what's
the difference?
2. The function has a second jstring argument, ticker,
that is not used (bad style, I know, but I didn't
write the code). Is it necessary to free the memory
for that jstring as well even though I don't use it?If you actually called to GetStringUTFChars successfully, I believed that memory will be allocated and hence, you should call ReleaseUTFChars to deallocate it.
Hope it helps :)

Similar Messages

  • Memory leak in  NFS server

    Hi all,
    I have a problem with 2 SunFire 240 (4Gb of Ram) with solaris 10 in a Veritas Cluster.
    These nodes are 2 NFS server and they have 10 nfs client.
    We have a memory leak on these servers. The memory utilization increase day by day.
    The memory seems to be allocated by the kernel and not from some process.
    So I would like to know if this is a common issue (NFS?) or this is a single case.
    Thanks in advance for you help
    Regards
    Daniele
    Edited by: Danx on Jan 2, 2008 5:23 PM

    That message relates to how the application deals with its threads, which for a the most part isn't actually an issue. However, since it does have the potential to cause a leak under certain circumstances we did make a change in 10.3 to address that issue, so I suggest you upgrade to that release.

  • How to deal with Memory Leaks, that are caused by Binding

    Hi, I recently noticed (huge?) memory leaks in my application and suspect bindings to be the cause of all the evil.
    I made a little test case, which confirms my suspicion:
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class TestAppMemoryLeak extends Application {
        public static void main(String[] args) {
            launch(args);
        @Override
        public void start(Stage stage) throws Exception {
            VBox root = new VBox();
            Button button = null;
            for (int i = 0; i < 100000; i++) {
                button = new Button();
                button.textProperty().bind(text);
                button.textProperty().unbind(); // if you don't call this, you can notice the increased memory of the java process.
            root.getChildren().add(button);
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.show();
        private StringProperty text = new SimpleStringProperty("test");
    }Now the problem is, HOW can I know, when a variable is no longer needed or overwritten by a new instance.
    Just an example:
    I have a ListView with a Cell Factory. In the updateItem method, I add a ContextMenu. The textProperty of each MenuItem is bound to a kind of global property, like in the example above. I have to do it in the updateItem method, since the ContextMenu differs depending on the item.
    So every time the updateItem method is called a new ContextMenu is created, which binds some properties, but the old context menus remain in memory.
    I guess there could be many more example.
    How can I deal with it?

    I've dealt with this situation and created a Jira issue for it, but I also have a work-around that is a bit unwieldy but works. I'll share it with you.
    The bug that deals with this (in part atleast): http://javafx-jira.kenai.com/browse/RT-20616
    The solution is to use weak invalidation listeners, however they are a bit of a pain to use as you cannot do it with something simplistic as "bindWeakly"... and you need to keep a reference around to the wrapped listener otherwise it will just get garbage collected immediately (as it is only weakly referenced). Some very odd bugs can surface if weak listeners disappear randomly because you forgot to reference them :)
    Anyway, see this code below, it shows you some code that is called from a TreeCell's updateItem method (I've wrapped it in some more layers in my program, but it is essentially the same as an updateItem method):
    public class EpisodeCell extends DuoLineCell implements MediaNodeCell {
      private final WeakBinder binder = new WeakBinder();
      @Override
      public void configureCell(MediaNode mediaNode) {
        MediaItem item = mediaNode.getMediaItem();
        StringBinding episodeRange = MapBindings.selectString(mediaNode.dataMapProperty(), Episode.class, "episodeRange");
        binder.unbindAll();
        binder.bind(titleProperty(), MapBindings.selectString(mediaNode.dataMapProperty(), Media.class, "title"));
        binder.bind(ratingProperty(), MapBindings.selectDouble(mediaNode.dataMapProperty(), Media.class, "rating").divide(10));
        binder.bind(extraInfoProperty(), Bindings.when(episodeRange.isNull()).then(new SimpleStringProperty("Special")).otherwise(episodeRange));
        binder.bind(viewedProperty(), item.viewedProperty());
        subtitleProperty().set("");
    }This code makes use of a class called WeakBinder -- it is a helper class that can make Weak bindings and can keep track of them. When you call unbindAll() on it, all of the bindings it created before are released immediately (although they will also disappear when the Cell itself is garbage collected, which is possible because it only makes weak references).
    I've tested this extensively and it solves the problem of Cells keeping references to objects with much longer life cycles (in my case, the MediaNode passed in has a longer lifecycle than the cells and so it is important to bind weakly to it). Before this would create huge memory leaks (crashing my program within a minute if you kept refreshing the Tree)... now it survives hours atleast and the Heap usage stays in a fixed range which means it is correctly able to collect all garbage).
    The code for WeakBinder is below (you can consider it public domain, so use it as you see fit, or write your own):
    package hs.mediasystem.util;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import javafx.beans.InvalidationListener;
    import javafx.beans.Observable;
    import javafx.beans.WeakInvalidationListener;
    import javafx.beans.property.Property;
    import javafx.beans.value.ObservableValue;
    public class WeakBinder {
      private final List<Object> hardRefs = new ArrayList<>();
      private final Map<ObservableValue<?>, WeakInvalidationListener> listeners = new HashMap<>();
      public void unbindAll() {
        for(ObservableValue<?> observableValue : listeners.keySet()) {
          observableValue.removeListener(listeners.get(observableValue));
        hardRefs.clear();
        listeners.clear();
      public <T> void bind(final Property<T> property, final ObservableValue<? extends T> dest) {
        InvalidationListener invalidationListener = new InvalidationListener() {
          @Override
          public void invalidated(Observable observable) {
            property.setValue(dest.getValue());
        WeakInvalidationListener weakInvalidationListener = new WeakInvalidationListener(invalidationListener);
        listeners.put(dest, weakInvalidationListener);
        dest.addListener(weakInvalidationListener);
        property.setValue(dest.getValue());
        hardRefs.add(dest);
        hardRefs.add(invalidationListener);
    }Let me know if this solves your problem.

  • Memory Leak with Flash Game - video of incident - Fix?

    My hypothesis:
    There is a memory leak in Flash Player that leads to Flash crashing, predictably and repeatedly, when used.
    My question:
    When will this problem be fixed?
    Evidence:
    Observe the progression in the following single-take video of me playing my favorite Flash game, posted to Youtube.  Skip to the times indicated in the "About" description for the video to observe the increase in use of physical memory, as observed in Windows Task Manager, until there isn't anything left.
    http://www.youtube.com/watch?v=gNIJvTuUitU
    My computer gets bogged down, the game stalls out, and Flash needs to be closed to enable my computer to function once more.  It makes it impossible to play this specific game for very long, and is an insidious problem lurking in the background every time I watch a video, play a game, or use Flash Player for any purpose.  My computer always slows down, with the problem worsening as time passes until I need to close everything and start again.
    Details:
    Flash Player Version: 11.7.700.224
    Operating System: Windows Vista (32-bit)
    Browser: Mozilla Firefox
    (Also happens when using Google Chrome)
    Conclusion:
    If you need further information about my specific computer, please feel free to ask.
    If this problem is specific to my computer, I would appreciate knowing this and determining a way to solve the problem.  My suspicion is that the problem originates in Flash Player itself and is experienced by many people in a variety of circumstances.  It is my hope that an articulate response indicating how long it will take to correct this bug in Flash Player can be provided.
    Thanks in advance for your help.

    My hypothesis:
    There is a memory leak in Flash Player that leads to Flash crashing, predictably and repeatedly, when used.
    My question:
    When will this problem be fixed?
    Evidence:
    Observe the progression in the following single-take video of me playing my favorite Flash game, posted to Youtube.  Skip to the times indicated in the "About" description for the video to observe the increase in use of physical memory, as observed in Windows Task Manager, until there isn't anything left.
    http://www.youtube.com/watch?v=gNIJvTuUitU
    My computer gets bogged down, the game stalls out, and Flash needs to be closed to enable my computer to function once more.  It makes it impossible to play this specific game for very long, and is an insidious problem lurking in the background every time I watch a video, play a game, or use Flash Player for any purpose.  My computer always slows down, with the problem worsening as time passes until I need to close everything and start again.
    Details:
    Flash Player Version: 11.7.700.224
    Operating System: Windows Vista (32-bit)
    Browser: Mozilla Firefox
    (Also happens when using Google Chrome)
    Conclusion:
    If you need further information about my specific computer, please feel free to ask.
    If this problem is specific to my computer, I would appreciate knowing this and determining a way to solve the problem.  My suspicion is that the problem originates in Flash Player itself and is experienced by many people in a variety of circumstances.  It is my hope that an articulate response indicating how long it will take to correct this bug in Flash Player can be provided.
    Thanks in advance for your help.

  • Memory Leak on SpoolSv.exe

    Hi
    I have a Windows 7 x64 (Ultimate) running on my laptop.  Weeks ago i started noticing weird errors like: "memory low", can not start virtual machine.  I wasn't running special memory consuming programs.  "A reboot a day keeps the troubles away" was my temporary workaround. 
    When i started digging into the problem, i noticed that memory usage of the process spoolsv.exe was rather high.  I have a screenshot of my task manager showing that the "Private Working Set" and also Commit Size is very large.  
    In the meantime, I have read in another post about a general memory leak in Windows 7 where they suggested using the driver verifier, but it didn't gave me any clue. I uploaded the screenshot of the driververifier.
    When the process is skyhigh in memory usage, i can kill it.  But a few minutes later i have taken these screenshots from the process explorer. 
    1) SpoolSv is using CPU.  Apparently it is not only consuming RAM but also CPU power.
    2) spoolsv.exe graph
    I am not printing, or have not printed since days (and several reboots).
    Normally I wouldn't care about (temporarly) high memory usage, but it really never drops...  Other programs do crash because the lack memory (like videodriver or skype).
    Has someone any idea why this process slows down my pc and keeps getting bigger minute after minute?
    Kind regards
    Please click 'Mark as Answer' on the post that helped you.

    Hi DamPee,
    In addition, I would like to suggest you perform the following steps to check the issue.
    Clear Printer Spooler Files and Restart the Spooler Service
    =================================
    1. Click Start, type "Services.msc" (without the quotation marks) in the Start Search box and press Enter.
    2. Double-click "Printer Spooler" in the Services list.
    3. Click Stop and click OK.
    4. Click Start, type "%WINDIR%\system32\spool\printers" in the Start Search box and press Enter, delete all files in this folder.
    5. Click Start, type "Services.msc" (without the quotation marks) in the Start Search box and press Enter.
    6. Double-click "Printer Spooler" in the Services list.
    7. Click on Start. In the Startup Type list, make sure that "Automatic" is selected and click OK.
    What’s the result?
    Arthur Li - MSFT

  • Possible memory leak in e4x or HTTPService with e4x format

    Hello,
    I think I have found a memory leak in e4x.
    In very special cases (=xml) the player swallows the memory.
    The little test program connects to a web server for an xml
    file, and the result is converted to an array.
    The array is displayed in a DataGrid.
    There are two files:
    leaktest.xml doesn't leak in any cases (format: e4x or xml)
    pbentries.xml leaks when the format is e4x.
    Choose e4x format and check Use "Leak" file! Than the program
    leaks.
    For the whole test case (mxml file, html file and xml files)
    please contact me at
    [email protected]
    or
    [email protected]
    and I send a zip file as soon as possible.
    Probably there is a bug in my test program. If so than please
    send me a feedback.
    Thanks,
    Lacito
    ------ For the program cut here ------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.managers.PopUpManager;
    import mx.core.Application;
    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.mxml.HTTPService;
    protected var records_:Array = null;
    protected var httpService:HTTPService = null;
    [Bindable("recordsChange")]
    public function set records(_records:Array):void
    this.records_ = _records;
    var e:Event = new Event("recordsChange");
    dispatchEvent(e);
    public function get records():Array
    return records_;
    protected function getXML():void
    var resultFormat:String = cbResultFormat.selectedItem as
    String;
    var params:Object = new Object();
    httpService = new HTTPService();
    httpService.concurrency = "single";
    httpService.showBusyCursor = true;
    var lastIndex:int = url.lastIndexOf("/");
    var fileName:String = null;
    if(chbUseLeakFile.selected)
    // It leaks... :(
    fileName = "pbentries.xml";
    else
    // It doesn't leak... :)
    fileName = "leaktest.xml";
    var _url:String = url.substr(0, lastIndex+1) + fileName;
    httpService.url = _url;
    httpService.resultFormat = resultFormat;
    httpService.method = "POST";
    httpService.addEventListener(ResultEvent.RESULT,
    processResult);
    httpService.addEventListener(FaultEvent.FAULT,
    processFault);
    httpService.send(params);
    protected function processResult(e:ResultEvent):void
    var resultFormat:String = cbResultFormat.selectedItem as
    String;
    removeListeners();
    if(resultFormat==mx.rpc.http.HTTPService.RESULT_FORMAT_XML)
    setArrayFromXMLNode();
    else
    setArrayFromXML();
    destroyHttpService();
    // format= "e4x"
    protected function setArrayFromXML():void
    var xml_:XML = httpService.lastResult as XML;
    var ar:Array = new Array();
    var x:XML = null;
    var xl:XMLList = xml_.phonebookEntries[0].phonebookEntry;
    for each(x in xl)
    var record:Object = new Object();
    var prop:XML = null;
    var props:XMLList = x.children();
    for each(prop in props)
    record[prop.localName()] = prop.toString();
    ar.push(record);
    records = ar;
    // format= "xml"
    protected function setArrayFromXMLNode():void
    var xml_:XMLNode = httpService.lastResult as XMLNode;
    var ar:Array = new Array();
    var x:XMLNode = null;
    var xl:Array = xml_.lastChild.childNodes;
    for each(x in xl)
    var record:Object = new Object();
    var prop:XMLNode = null;
    var props:Array = x.childNodes;
    for each(prop in props)
    record[prop.localName] = prop.firstChild!=null ?
    prop.firstChild.nodeValue : null;
    ar.push(record);
    records = ar;
    protected function destroyHttpService():void
    httpService.clearResult(false);
    httpService.disconnect();
    httpService = null;
    protected function processFault(e:FaultEvent):void
    removeListeners();
    Alert.show(e.fault.faultString, e.fault.faultCode);
    destroyHttpService();
    protected function removeListeners():void
    httpService.removeEventListener(ResultEvent.RESULT,
    processResult);
    httpService.removeEventListener(FaultEvent.FAULT,
    processFault);
    protected function collect():void
    // Garbage Collection
    try
    new LocalConnection().connect('foo');
    new LocalConnection().connect('foo');
    catch(e:*)
    ]]>
    </mx:Script>
    <mx:ArrayCollection id="alRecords" source="{records}"
    />
    <mx:Label x="10" y="10" text="Result format:"
    id="lResultFormat"/>
    <mx:ComboBox x="104" y="8" id="cbResultFormat">
    <mx:Array>
    <mx:String>e4x</mx:String>
    <mx:String>xml</mx:String>
    </mx:Array>
    </mx:ComboBox>
    <mx:DataGrid id="dgRecords" x="10" y="36" width="936"
    height="437"
    dataProvider="{alRecords}"
    verticalScrollPolicy="auto"
    horizontalScrollPolicy="auto">
    </mx:DataGrid>
    <mx:Button x="355" y="496" label="Get xml" id="btnGetXML"
    click="{getXML();}" />
    <mx:Button x="155" y="496" label="GC" id="btnGC"
    click="{collect();}" />
    <mx:CheckBox x="276" y="10" label="Use
    &quot;LEAK&quot; file:" labelPlacement="left"
    id="chbUseLeakFile" selected="true"/>
    </mx:Application>

    Hello,
    After 3 months (and a new version of flex and flash player)
    my test program is still leaking.
    If somebody could confirm the leak it would be appreciated.
    Thanks,
    Lacito
    P.S.: I heard that Adobe had donated ActionScript 3 VM to
    Mozilla.org. Should I disturb them with my problem?

  • Memory leak problem

    Dears,
    I have an application which have pages, each page has its content from text, images and external swfs.
    I load page only if user navigate to it, by the time, more navigation by user occures and more pages loaded.
    I don't kill ( also I couldn't kill, no destroy in as3 ) pages, becuse i need them when user go back again to it, specially that pages have interactive content which user can deal with it, like questions, so I need prevoius pages which user enterd, its content and user's data.
    The big problem is the Memory leak, the application becomes heavy , what can i do ?
    Also, if I should kill pages with its content and use GC, How can i do that ? - there is a long life and events of objects in my application.
    thank you in advance,
    heba

    I use Flash Builder , flex sdk 4.5, flash player 11.4, and windows 7 64bit
    thank you,

  • Memory leaks in MFC while using CDatabase::OpenEx()

    Hi,
    This question has been asked previously but the explanation was not in detail and i could never reach to the bottom of it.
    I hope i can elaborate more on the problem statement and i can get a resolution/explanation from the experts here.
    Consider the following two sample codes;
    1.
    int count = 200;
    for (int i=0; i <count; ++i)
    try
    CDatabase *db = new CDatabase;
    BOOL bRes = db->OpenEx(_T("DSN=MyData;UID=anon;PWD=pass"));
    db->Close();
    delete db;
    db=NULL;
    catch (CDBException* e)
    e->Delete();
    2.
    CDatabase *db = new CDatabase;
    int count = 200;
    for (int i=0; i <count; ++i)
    try
    BOOL bRes = db->OpenEx(_T("DSN=MyData;UID=anon;PWD=pass"));
    db->Close();
    catch (CDBException* e)
    e->Delete();
    delete db;
    db=NULL;
    return 0;
    delete db;
    db=NULL;
    The first sample code leaks a lot of memory and it can be easily observed from the task manager, the memory usage keeps on growing.
    The second sample code does not leak any memory if i observe the memory usage from the task manager.
    To find out the cause of the memory leak i ran the code through rational purify, both the codes are leaking memory according to rational purify. The first code leaks significantly more memory than the second one. The DLL pointed by rational purify are MFC
    DLLs (inserting the screen shot below)
    Is this a known issue with the MFC DLL or am i doing something wrong?
    I have a server application where i have to create CDatabase object multiple times and i end up leaking a lot of memory over a period of time.
    I can provide more information about this issue if required. Thanks in advance.

    I am trying to reproduce this issue on my side, but it seem there is no memory leak in my simple sample. I use _CrtDumpMemoryLeaks() to test the memory leak.
    https://msdn.microsoft.com/en-us/library/d41t22sb.aspx
    If I comment this line: db->Close();
    I can detect the memory leak at CDatabase
    *db =
    new CDatabase; 
    See the screenshot.
    If follow your sample code, there is memory leak message in the output view pane.
    #define CRTDBG_MAP_ALLOC
    #include <stdlib.h>
    #include <crtdbg.h>
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif.....int CMFCCdbMLTestApp::ExitInstance()
    // TODO: Add your specialized code here and/or call the base class
    _CrtDumpMemoryLeaks();
    return CWinApp::ExitInstance();
    May you can use some use tool like WinDbg tool to find more information about this issue. 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Is there a memory leak in IXML library?

    Hi,
    I wonder if there is a memory leak in the IXML library. Using the memory inspector I observed that memory consumed while building a DOM-tree is never released. Is there some special cleanup method I have to call to free all memory consumed by my DOM tree? I tried to explicitly remove the node to free memory, but that seems not to work (look at my example report below).
    Regards,
    Michael
    REPORT  Z_IXML_TEST                                               .
    data:
      lr_ixml type ref to if_ixml,
      lr_dom type ref to if_ixml_document,
      lr_element type ref to if_ixml_element,
      l_rc type i.
    class cl_ixml definition load.
    lr_ixml = cl_ixml=>create( type = 0 ).
    lr_dom = lr_ixml->create_document( ).
    at this point you see 1 string in Memory Inspector after creating a snapshot
    lr_element = lr_dom->create_element( name = 'root' ).
    call method lr_element->set_attribute( name = 'attrName1' value = 'attrValue1' ).
    call method lr_element->set_value( value = 'value1' ).
    call method lr_dom->append_child( new_child = lr_element ).
    at this point you see 5 strings in Memory Inspector after creating a snapshot
    l_rc = lr_dom->remove_child( old_child = lr_element ).
    lr_element->remove_node( ).
    lr_dom->remove_node( ).
    free lr_element.
    free lr_dom.
    free lr_ixml.
    at the latest at this point you would expect 1 string again, but there are still 5!

    Answer in
    SAP Note 1081257 Memory leak in the iXML library 

  • How can memory leaks occur?

    Hi,
    I was just wondering how a memory leak can occur in Java. The garbage collector is supposed to free up all unused variables, so under what circumstances can it happen?

    This is not technically a "memory leak". I've seen
    this called "loitering objects", which conjures upa
    vivid picture: objects hanging around with nothingto
    do...I think it's the classic java memory leak. A bug in
    a program that prevents the freeing up of memory that
    it no longer needs.Yes, but it's not what is traditionally termed a memory leak.
    A real memory leak is memory that's claimed by the program but no longer accessible to the program for freeing up.
    That can in Java (where what we call a program isn't a complete program but runs inside a virtual machine which handles memory allocation and deallocation) only happen if there's a flaw in the JVM itself which causes errors in memory deallocation (so most likely a flaw in the garbage collector).
    In Java the objects you create are always out there somewhere where something can reach them so as to prevent them from being available to the garbage collector.
    Different cause, same effect in that in both cases memory isn't getting freed for reuse.

  • 2008 R2 - Memory Leak from svchost.exe - Module "rpcrt4" is the culprit

    Hi All
    Over the past week or so (after a set of Windows updates and restart) svchost.exe has increasingly used more and more memory. It probably gobbles up an extra 1GB per day and doesn't relent. 
    After running various diagnostics, the debug diagnostic tool finally provided me this information after a memory leak test:
    rpcrt4.dll is responsible for 1.76 GBytes worth of outstanding allocations. The following are the top 2 memory consuming functions:
    rpcrt4!AllocWrapper+2b: 1.76 GBytes worth of outstanding allocations.
    rpcrt4!Ndr64ClientInitialize+964: 1.36 MBytes worth of outstanding allocations.
    Detailed module report(Memory)
    Module details for rpcrt4
    Module Name   rpcrt4 
    Allocation Count   946941 allocation(s) 
    Allocation Size   1.76 GBytes 
    Module Information 
    Image Name: C:\Windows\System32\rpcrt4.dll   Symbol Type:  PDB 
    Base address: 0x00000003`00905a4d   Time Stamp:  Sat Nov 20 13:13:18 2010  
    Checksum: 0x00000000`00000000   Comments:   
    COM DLL: True   Company Name:  Microsoft Corporation 
    ISAPIExtension: False   File Description:  Remote Procedure Call Runtime 
    ISAPIFilter: False   File Version:  6.1.7601.17514 (win7sp1_rtm.101119-1850) 
    Managed DLL: False   Internal Name:  rpcrt4.dll 
    VB DLL: False   Legal Copyright:  © Microsoft Corporation. All rights reserved. 
    Loaded Image Name:  rpcrt4.dll   Legal Trademarks:   
    Mapped Image Name:     Original filename:  rpcrt4.dll 
    Module name:  rpcrt4   Private Build:   
    Single Threaded:  False   Product Name:  Microsoft® Windows® Operating System 
    Module Size:  1.18 MBytes   Product Version:  6.1.7601.17514 
    Symbol File Name:  c:\symcache\rpcrt4.pdb\7D748DA6D7454C9EA38C8CEF1C9E75F22\rpcrt4.pdb   Special Build:  & 
    rpcrt4!AllocWrapper+2b  has 944,468 allocations! 
    I'm running 2008 R2 64bit with anywhere up to 80/100 simultaneous RDP connections at any one time.
    Can anyone help or advise as I cannot find any hotfixes for this issue.
    Thanks
    Ryan

    Hi Ryan,
    Please narrow it down to the specific service that is having the issue.  That way you will know where to focus on.
    For the specific svchost.exe that is showing the large memory usage, use task manager/process explorer/etc. to determine which service(s) are running within it.  If there are multiple services running within it, I recommend you isolate them and then
    restart your server.  For example, say you determined that the following services are running in the "problem" svchost.exe: AudioEndpointBuilder, Netman, TrkWks, UmRdpService, Uxsms.  You would open an admin command prompt and enter the following
    commands:
    sc config AudioEndpointBuilder type= own
    sc config Netman type= own
    sc config TrkWks type= own
    sc config UmRdpService type= own
    sc config Uxsms type= own
    After entering the above commands you would restart your server for the changes to take effect.  Over time you would monitor memory usage of the suspect services, and eventually it will become apparent which one is using too much memory.
    Thanks.
    -TP

  • Memory leak linux

    I'm running Ubuntu Linux and it looks like I see a memory leak that I'm not seeing when I ran it on my PC.
    I get heap exception everntually. I was using sam maxm heap size of 500M.
    Is there anything I have to do special for linux?
    Thanks

    morgalr wrote:
    Yes, my crystal ball says to fix the leak you observe in Linux, and it will fix any potential problem you have not viewed in Windows yet.(chuckle) Your comment expresses something that flicked through my mind even reading the title. The thought that flicked through my mind, did not quite have the eloquence of your words.

  • Can Java program cause memory leak?

    Can Java program cause memory leak or memory crash? I don't mean any memory overflow related exceptions. I mean something like core dump in UNIX or error reports in Windows XP.
    If it can really happen, in what circumstances? I raise such a question because our J2EE based system had really caused memory leak in Windows XP systems, but so far we still fail to troubleshoot the problem.

    Your code may leak memory. There are many, many, many reasons this could be. All of them represent bugs in your code.
    You should get a profiler to identify the problem spots of your code.
    You spoke of a memory crash as well. The VM may crash with some bug in the VM, or a bug in native code but that is not relevent to your problem. A memory leak is a problem in your code.

  • How to determine memory leaks?

    I tried in XCODE, the RUN/ Start with Performance TOol / and tried out the various options. I was running my app and looking to see if it would report increasing memory use but it seemed to be looking at my total system (i was running under the simulator). In general what is the recommended procedure for determining memory leaks, which tool to use, and what tracing can i use?
    How does one look at the retain count of an object? are there system routines that have knonw leaks?

    You took the right path. Once instruments comes up select the Leaks tool. Turn off automatic leak detection. In your app, start off at some known state, do something, and come back to the known state and check for leaks. For instance start off in a view, do something that brings up another view then come back to the original view and check for leaks. Leaks will show you if you leaked. Since you took a very deterministic path then checked it should be straight forward to go to the code and find / fix the leaks. Leaks shows you where the code where the leak was generated.

  • Memory leak in JSpinner implementation (maybe others?)

    Hi,
    I am developing an application using Java and Swing, and have run into some problems with memory leaks. After examining the source code and making an example program (provided below), I can only come to the conclusion that there is a bug in the implementation of JSpinner in Sun Java 1.6.0_03.
    If one uses a custom model with the JSpinner, it attaches itself as a listener to the model. However, it never removes the listening connection, even if the model is changed. This causes the JSpinner to be kept in memory as long as the model exists, even if all other references to the component have been removed.
    An example program is available at http://eddie.dy.fi/~sampo/ModelTest.java . It is a simple swing program that has the JSpinner and two buttons, the first of which writes to stdout the listeners of the original model and the second changes the spinner model to a newly-created model. A sample output is below:
    Running on 1.6.0_03 from Sun Microsystems Inc.
    Listeners before connecting to JSpinner:
      Model value is 0, 0 listeners connected:
    Listeners after connecting to JSpinner:
      Model value is 0, 2 listeners connected:
      1: interface javax.swing.event.ChangeListener
      2: javax.swing.JSpinner$ModelListener@9971ad
    Listeners now:
      Model value is 8, 2 listeners connected:
      1: interface javax.swing.event.ChangeListener
      2: javax.swing.JSpinner$ModelListener@9971ad
    Changing spinner model.
    Listeners now:
      Model value is 8, 2 listeners connected:
      1: interface javax.swing.event.ChangeListener
      2: javax.swing.JSpinner$ModelListener@9971adThis shows that even though the model of the JSpinner has been changed, it still listens to the original model. I haven't looked at other components whether they retain connections to the old models as well.
    In my case, I have an adaptor-model which provides a SpinnerModel interface to the actual data. The adaptor is implemented so that it listens to the underlying model only when it itself is being listened to. If the JComponents using the model were to remove the listening connections, it, too, would be automatically garbage-collected. However, since JSpinner does not remove the connections, the adaptor also continues to listen to the underlying model, and neither can be garbage-collected.
    All in all, the listener-connections seem to be a very easy place to make memory leaks in Java and especially in Swing. However, as I see it, it would be a simple matter to make everything work automatically with one simple rule: Listen to the models only when necessary.
    If a component is hidden (or alternatively has no contact to a parent JFrame or equivalent), it does not need to listen to the model and should remove the connections. When the component is again set visible (or connected to a frame) it can re-add the connections and re-read the current model values just as it does when initializing the component. Similarly, any adaptor-models should listen to the underlying model only when it itself is being listened to.
    If the components were implemented in this way, one could simply remove a component from the frame and throw it away, and automatically any listener-connections will be removed and it can be garbage-collected. Similarly any adaptor-models are collected when they are no longer in use.
    Changing the API implementation in this way would not require any changes to applications, as the only thing that changes are the listener-connections. Currently used separate connection-removing methods should still work, though they would be unnecessary any more. The API would look exactly the same from the view of an application programmer, only that she would not need to care about remnant listening connections. (As far as I can tell, the current API specification would allow the API to be implemented as described above, but it should of course require it to be implemented in such a way.)
    Am I missing something, or is there some valid reason why the API is not implemented like this?
    PS. I'm new to these forums, so if there is a better place to post these reports, please tell me. Thanks.

    Another cognition: It's the following code, that causes the memory to be accumulated:
    obj = m_orb.resolve_initial_references("NameService");
    ctx = NamingContextExtHelper.narrow(obj);For the first 4 calls to this code the memory usage of the nameservice is unchanged. From the 5th to the 8th call, it's increased by approx. 10KB per call. And thenceforward (beginning with the 9th call) it's increasing by approx. 10MB.
    What's going wrong here?

Maybe you are looking for

  • How do you install the same Apple ID on two ipads

    I have an original ipad and just purchased an ipad air.  I want to use the same Apple ID and it won't let me.  Is there a way to do this?

  • How can i remove JUNK TEXT from APEX

    Hi , In our project Apex has integrated with oracle apps,every time we will open apex front end from oracle application(EBS).so we have two kinds of instances 1) development and other is production every time we export the apex application from devel

  • ITunes is blank!

    I pulled up my iTunes the other day and it was completely blank? Not sure how it happened, but I haven't touched the iTunes file in "my music". Now even when I plug the iPod into the computer, the iTunes is still blank. There were over 1000 songs on

  • Query Tables

    Hello everybody, I was wondering if somewhere in the system, the filters on the queries are stored together with some query's parameter in a table. Let's suppose I filter the 0COMP_CODE - Company code by just one fixed company "GXXX"... are the "GXXX

  • Blocked details.

    Dear friends, Please help to know the T. Code or where I can find the list of Blocked stocks details. (MMBE I can find for only 1 material and don’t have table level authorization to check in tables). Best regards, Raman.