Memory leak when using Threads?

I did an experiment and noticed a memory leak when I was using threads.. Here's what I did.
======================================
while( true )
     Scanner sc = new Scanner(System.in);
     String answer;
     System.out.print("Press Enter to continue...");
     answer = sc.next();
     new TestThread();
========================================
And TestThead is the following
========================================
import java.io.*;
import java.net.*;
public class TestThread extends Thread
public TestThread() { start(); }
public void run() {  }
=====================================
When I open windows Task Manager, every time a new thread starts and stops, the java.exe increases the Mem Usage.. Its a memory leak!? What is going on in this situation.. If I start a thread and the it stops, and then I start a new thread, why does it use more memory?
-Brian

MoveScanner sc = new
Scanner(System.in);out of the
loop.Scanner sc = new Scanner(System.in);
while (true) {
That won't matter in any meaningful way.
Every loop iteration creates a new Scanner, but it also makes a Scanner eligible for GC, so the net memory requirement of the program is constant.
Now, of course, it's possible that the VM won't bother GCing until 64 MB worth of Scanners have been created, but we don't care about that. If we're allowing the GC 64 MB, then we don't care how it uses it or when it cleans it up.

Similar Messages

  • Memory leak when using DB_DBT_MALLOC in CDB.

    Hello!
    Recently when I'm using Berkeley DB CDB and set the value Dbt DB_DBT_MALLOC, I noticed that the app's memory keeps growing during the db.get while;
    I found that many codes on the internet use the syntax free(value.get_data()), but when I tried to free the value.get_data(), I always got an interruption error.
    It's OK when I'm using the DB_DBT_USERMEM flag. So I just get very confused about the DB_DBT_MALLOC and DB_DBT_REALLOC.
    And also, I wonder why there's no memory leak problem when we use the single thread BDB. I think BDB cannot free the value.data pointer too in single thread before the app finish using it, then why our apps don't need to free the data afterwards?
    Thanks a lot in advance!

    You should use free() to free the DBT memory allocated via DB_DBT_MALLOC. You should do that after each Db::get() operation (and of course after finishing processing/using the data), otherwise you will loose the pointer to the memory previously allocated if you happen to reuse the DBT with DB_DBT_MALLOC (the data field will point to a new memory address).
    Alternatively you could use DB_DBT_REALLOC or DB_DBT_USERMEM.
    Note that there are small structures that BDB creates in the environment regions that only get freed/cleaned when the environment is closed.
    If you suspect that there is a memory leak inside the BDB code, make sure you rebuild Berkeley DB using the following configuration options (along with the others you use) when building: enable-debug, enable-umrw. Than, run the program under a memory leak detection utility, like Valgrind (allow the application to open and close the BDB environment) and see if there are any leaks reported.
    If memory leaks are reported, then put together a small stand-alone test case program that demonstrates the leaks, and post it here.
    Regards,
    Andrei

  • Memory leak when "Use JSSE SSL" is enabled

    I'm investigating a memory leak that occurs in WebLogic 11g (10.3.3 and 10.3.5) when "Use JSSE SSL" is checked using the Sun/Oracle JVM and JCE/JSSE providers. The leak is reproducible just by hitting the WebLogic Admin Console login page repeatedly using SSL. Running the app server under JProfiler shows byte arrays (among other objects) leaking from the socket handling code. I thought it might be a general problem with the default JSSE provider, but Tomcat does not exhibit the problem.
    Anyone else seeing this?

    Yes, we are seeing it as well on Oracle 11g while running a GWT 2.1.1 application using GWT RPC. Our current fix is to remove the JSSE SSL configuration check, however this might not be an option if you really need it for your application. Have you found anything else about it?

  • Memory leak when using database connectivity toolset and ODBC driver for MySQL

    The "DB Tools Close Connection VI" does not free all the memory used when "DB Tools Open Connection VI" connects to "MySQL ODBC Driver 3.51".
    I have made a small program that only opens and close the connection that I run continously and it's slowly eating all my memory. No error is given from any of the VI's. (I'm using the "Simple Error Handler VI" to check for errors.)
    I've also tried different options in the DSN configuration without any results.
    Attachments:
    TestProgram.vi ‏16 KB
    DSNconfig1.jpg ‏36 KB
    DSNconfig2.jpg ‏49 KB

    Also,
    I've duplicated the OPs example: a simple VI that opens and closes a connection. I can say this definately causes a memory leak.
    Watching the memory:
    10:17AM - 19308K
    10:19AM - 19432K
    10:22AM - 19764K
    10:58AM - 22124K
    Regards,
    Ken
    Attachments:
    OpenCloseConnection.vi ‏13 KB

  • Makequeues memory leak when using Lexmark Z53

    Behavior with printer switched off while connected to built-in USB port:
    Problem 1: makequeues has a memory leak, starting up with between 3 and 5 MB of RAM. This is done by connecting the printer when logged in and watching via Activity Monitor.
    Initially makequeues has sent 255 Mach messages. Every ~10.5 seconds, makequeues sends 59 more messages and gets 53 in reply. With each send/receive cycle, its RAM usage grows by 8 KB, a rate of 780 kiB/min.
    Problem 2: The process is started each time the same printer is reconnected.
    Symptoms: Disconnecting the printer doesn't let the process exit (any instance). If left alone, the memory usage cycle continues.
    The memory leak caught my attention after taking up over a half-gigabyte of RAM when I left the Mac running over night.
    Resolution:
    (1) Disconnect USB cable
    (2) Kill each instance of the process
    Results:
    (1) The process launches after reconnection of the printer with 996 KB of RAM, immediately having sent 60 Mach messages and received 56.
    (2) During this run time, the process may use less and less RAM, down to a minimum of 912.
    (3) After sending 64 more messages without replies, one every 4 seconds, the process exits after having sent a total of 120 messages.
    (4) This behavior (1 through 3) is the same for each process launched as a result of printer reconnection.
    This behavior isn't shown during Safe Mode boot - makequeues never starts up as a result of printer connection.
    PowerMac G4 QuickSilver 2001 733Mhz

    If this is meant to be a bug report, please file a bug report in the proper place. This is a user to user discussion forum.
    As to the source of running 'makequeues' (/System/Library/SystemConfiguration/PrinterNotifications.bundle/Contents/MacOS /makequeues), I would look at the Lexmark software. I currently have two Epson printers connected via USB with CUPS running. I see no process 'makequeues' appearing.
    Matt

  • Memory leak when using JMS Cache Coordination

    We have two Weblogic Server 8.1 processes running Java 1.4.2 on Solaris using TOPLink 10.1.3 with JMS Cache Coordination. We observe that heap is filled with uncollectable instances of TOPLink-mapped classes. In our production system, under full load, this completely fills a 3.6 GB heap in 30 minutes, requiring a process restart. The problem goes away if we turn off cache coordination.
    It appears that these instances are UnitOfWork or some other kind of toplink-created clone. We have not yet been able to successfully analyse this problem with a heap profiler.
    Has anyone else experienced this this problem? Any suggestions for debugging?
    Thanks in advance.

    We do set the command manager to asychronous mode. (Our debug tracing confirms that the CommandPropagator method asynchronousPropagateCommand() is invoked, not synchronousPropagateCommand().) We started with asynchronous messaging and actually have never tried running in a synchronous mode.
    The Java bug I referenced in my last post (which I have confirmed with a stand-alone test case) indicates that, for Java 1.4.2 and earlier, is is never ok to not start() a Thread -- it will always produce a memory leak. So I am quite surprised than anyone on a pre-1.5 Java had ever had success with synchronous cache coordination messaging. Do you think it is possible all of the pre-release tests and existing customers installations of 10.1.3 cache coordination are using Java 1.5 ?!
    Our heap profiling indicates that the instances of CommandPropagator which are pinned (i.e., those not started) are allocated in the run() method of CommandPropagator itself. So it seems that the instance of CommandPropagator, after it is started, allocates another one in its run method. Looking at the bytecodes for the run() method (using javap -c) shows that in one branch of the code a second CommandPropagator is indeed allocated and then handed off to the launchContainerRunnable method of a ServerPlatform.
    Since these secondary CommandPropagators are the ones which are not started, we have looked into the WebLogic_8_1_Platform class and found that its implementation launchContainerRunnable (inherited from ServerPlatformBase) does a
    new Thread(runnable).start()where the argument runnable is the CommandPropagator.
    So the CommandPropagator itself is not started(), but is instead run an another Thread.
    We are experimenting with a custom ServerPlatform which overrides launchContainerRunnable:
        server.setServerPlatform(
            new WebLogic_8_1_Platform(server)
                public void launchContainerRunnable(Runnable runnable)
                   if (runnable instanceof Thread) ((Thread)runnable).start();
                   else super.launchContainerRunnable(runnable);
        );  This starts the argument Runnable directly if it is actually a Thread. Our early, small-scale tests indicate that this change eliminates the memory leak. We are testing now in a production-replicate environment under full load.
    But this feels like a hack. I have no idea what TOPLink behavior other than cache coordination flows through this method. Does anyone know what else this ServerPlatform method is used for? Is there a better way to do this? Are there any adverse conquences to our hack? Any suggestions would be appreciated.
    Thanks in advance.

  • Memory Leak when using Active X and/or Modbus commands

    I am using a piece of hardware connected by ethernet to my PC with its own IP address. The unit sends me data from my test rig (16 differential channels) such as voltage, current, temp, pressure etc.
    I am able to use ActiveX commands to get the data sent back. I am sampling data at about 1 second intervals and graphing it within Labview. The problem is that Labview consumes memory at about 4K every minute. I open a connection to the IP address send the ActiveX command receive the string of characters back and then close the connection (this procedure is repeated every second). The advice given by NI engineers was that it was the limitation of ActiveX communication layers, so I set about using Modbus TCP/IP instead.
    I searched the knowledge base and found an example of using Modbus to communicate to a Festo controller written by an NI engineer. I adapted this to suit reading back one input register starting at address 1 and found it obtained the data from my own piece of hardware. Again, running this in a 1 second interval a memory leak of about 4K/minute occurs.
    Neither approach is satisfactory as tests must run for months at a time without interruption.
    Is the problem therefore not to do with Labview and not the communication layer protocols?
    A solution would be greatly appreciated!!

    I've attached both the ActiveX vi   and the Modbus vi code
    Attachments:
    ActiveX.vi ‏58 KB
    Modbus.zip ‏658 KB

  • HUGE memory leak when using MP3

    I downloaded a new FME 2.0 and noticed they added an option
    to stream in MP3 format. DO NOT USE that mode (!). If you start
    streaming in MP3 format you will get a huge memory leak on the
    client side. Your browser starts eating memory like crazy and it
    will bury your machine withing an hour or two by taking all the
    memory available. I have proved it on several machines, notifed
    Adobe. They confirmed it as a bug and promised to fix in the future
    releases. Nice, huh? and what people are supposed to do with the
    current build?

    A new build 2.0.1.1114 has been posted . Please try and let
    us know if you face this issue with this build.

  • I am experiencing a memory leak when using ajax calls, only in Firefox 4.

    I have been developing an intranet application that uses jquery's ajax function to refresh certain parts of a page. I have tested this application in Firefox 4, IE9 and Chrome 11 on a Windows 7 64-bit machine.
    Only Firefox is seeing an increase in memory usage, leading me to believe there may be an issue with how Firefox is handling these types of calls.
    I have been investigating this issue for two solid days now and have come across solutions to similar issues for slightly different configurations, but none have solved the problem I am experiencing.
    The software and versions I have been using are:
    Windows 7 64-bit
    Firefox 4.0.1
    jQuery 1.6.1
    Any assistance or even a clarification that the issue exists would be helpful.

    The behaviour you describe is strange. Something to try: Open a refernce to the file one time before entering the loop, then inside the loop use that reference to do all the writing. Finally close the reference when the loop completes.If this doesn't work, post your code in 6.0 format and I'll be glad to look at it.Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • JVM - Microsoft JScript.dll Memory Leak when using Java Web Start

    I have posted before a topic related to this matter, although now I have a lot more information about what is going on (although still no fix for it). This is the link to the earlier post, containing JVM HOTSPOT EXCEPTION_ACCESS_VIOLATION
    http://forum.java.sun.com/thread.jspa?threadID=5116970&messageID=9402346#9402346
    The issue is that after deploying on Windows XP a multi threaded, memory consuming (40 Mb) Java Swing application using Java Web Start, and the standard web page (IE6) reference to the jnlp file to launch the installation from Tomcat, each time this application gets executed by double clicking on the desktop icon (with no IE6 interaction at all), calls start being made between jvm.dll (sun) and jscript.dll (Microsoft IE), these interactions never release the memory they consume, so after a period of using the application it crashes unavoidably. If I execute exactly the same application launching it from command line (no Web Start nor IE6 browser involved), the application works nicely all the time, no problem at all.
    My question is: does anyone know why these calls to jscript.dll are even being made during web start application execution? As said, it's a desktop Swing app, it does not need the browser at all, and jscript.dll is a IE dll. Anyone can advice on how these interactions can be eliminated?
    I've worked with Microsoft support for two weeks on this issue and all they have said is that it is a Sun problem and they can not help further.
    Thanks
    Jes�s

    Microsoft suggested (among others) two test.
    1- Install IE7 and run the application
    2-Install Firefox and run the application
    Results were:
    For 1: The application does not crash, apparently IE7 has a newer version of Jscript.dll that, in Microsoft words, handles better 'bad software', refering to 'bad software' to the java virtual machine I guess. Looking at the performance manager you can see memory goes down as with IE6, but at some point memory is released and the app. does not crash. Anyway is still is uncertain to me why Jscript.dll is getting involved at all. Although this solves the problem is not a viable solution for us, because I work in a corporation where changes such as upgrading the IE version on a large number of desktop can not be justified just because one app. is crashing, and it would take a long validation time anyway before the upgrade can proceed.
    For 2: I did install Firefox in a machine and the application still crashed, but it is true I did not uninstall IE6, so the conflictive Jscript.dll was still sitting at system32. Quite possibly the crash would not happen if that dll wasn't there at all.
    Thanks
    Jes�s

  • Memory leak when using worker

    Set byteArray as sharedProperty.
    Write data to byteArray.
    Set byteArray length to zero.
    Clear byteArray.
    Memory use is bigger and bigger.
    Bug#3555791

    I have no new information at this time.  The bug is open and assigned.  We'll list the bugfix in the announcement in the Beta Forums and will update the bugbase when the issue is resolved.
    Thanks,
    Jeromie

  • Could not resolve memory leak when using QuadArray  BY_REFERENCE

    Hi,
    While working on my project I have to create large mesh (grid). To do it I am using QuadArray and using BY_REFERENCE mode.
    After I close the module, the float array that is used as the coordinates array for above QuadArray geometry, is not freed. And if I open same module it takes additional same amount of memory. If I open that module for 3-4 times, memory goes piling up and causing OutOfMemoryError.
    Even I have nullified the coordinate array explicitly on closing the module, the problem could not be resolved.
    Can any body please help and give me some points where the problem may be rooted.
    Regards,

    I found the solution
    if I set the coordinate array to null memory frees up.
    The code line look like
    g.setCoordRefFloat(null);Probably reference kept by geometry was not being freed.
    cheers!

  • Massive memory leak when using Google (normal search, inactive, but logged into Google+)

    Firefox has massive memory usage in recent times (runs up to over 3GB on Win7x64HP). I was not sure until now what caused it, since I have the browser open in the background most of the time. Commonly open pages are facebook, some news site (containing flash ads) and some other stuff for doing research. And Google - of course.
    Normally I killed Firefox completely whenever I recognized the memory usage was way above normal, but this time I just kicked the google tab and (after 2mins of HDD action) the mem usage dropped by 2GB! I have no idea what causes this, but the rise of allocated mem is always very slowly and seems to build up over the day (2-3 times stand-by or hibernation included). I also just realized that the google tab keeps cpu usage of FireFox constantly by around 2%. An important side note: FF automatically logs on to Google+, maybe that's one of the reasons.
    Has anyone the same issues? Is it rather a the fault of FF or Google? Will try surfing with Extensions deactivated the next days to see if the behavior continues...

    If you go to ''about:memory'' in the location bar you may find some of the info there of use, explanatory notes appear on mousover. It will help you figure out where the memory is going to.
    * see also [[high memory usage]]
    Some of the developers have been trying recently to improve how firefox uses memory, and have recently added ''about:memory'' as a diagnostic feature.
    Using 3GB of memory for firefox is obviously abnormal, however some sites you use may be fairly intensive. It does often take quite a bit of effort to track down such problems, but sometimes new problems are identified and then fixed: either problems with firefox, or with specific sites or software.

  • Memory Leak when TOMCAT connects to Oracle 10g RAC using JDBC Thin driver.

    We had experienced Memory leak when a Oracle 10g (10.2.0.3) RAC node was evicted. TOMCAT app server is connecting to the Oracle 10g RAC database instances using JDBC 10.2.0.3 thin driver.
    Anyone had similar experience?
    Any ideas? Any bugs reported/fixed?
    Thanks,
    Raj

    If you're doing XA, we absolutely do not support
    driver-level load-balancing OR failover. Use neither.
    For non-XA, you can use driver-level failover. For
    non-XA, you could set load-balancing, but it won't
    help because we get connections from the driver,
    and keep them indefinitely, so the driver never gets
    the chance to affect which connections the pool
    uses after that.

  • Memory Leak when running Contacts

    I am having a big memory leak when running the app Contacts on a MB Air. It gobbles up 2 GB of ram in just a few minutes forcing a reboot. I have re-installed Mountain Lion 10.8.2 and it still leaks memory. Watching Activity Monitor shows the rapid increase in Ram being gobbled up by Contacts. Used Mackeeper to clear cache as well as ran Cocktail, all to no avail. Any tips would be greatly appreciated.

    The size of oracle.exe is not an indication of how the Java VM GC works; so you are not comparing apples to apples. It'll be too long to explain here but in my upcoming book (see hereafter), I gave a detailled explanation of the various memory areas the Java VM uses and how these are GCed and also how you can meausre their size (not all, though).
    In short you want to use OracleRuntime methods such as
    OracleRuntime.getSessionSize(); --> get he current size of Sessionspace
    OracleRuntime.getNewspaceSize(); --> get he current size of Newspace
    there are other memory areas described in the book
    http://www.oracle.com/technology/pub/articles/mensah_dws.html
    http://www.elsevier.com/wps/find/bookdescription.cws_home/706089/description#description
    Sample chapter: http://www.oracle.com/technology/books/pdfs/mensah_ch1.pdf
    Kuassi

Maybe you are looking for

  • Java EE tutorial, problem with ANT populating database

    Hi! I have followed the instructions in the Java EE tutorial to set up the enviroment but when I execute the command "ant create tables" I get this output: C:\javaeetutorial5\examples\web\bookstore1>ant create-tables Buildfile: build.xml -pre-init: i

  • Received for my shipment, but there is the size of memory error

    Apple estimable Greetings Received for my shipment, but there is the size of memory error I got up at the request of any device iPhone 5 golden color 64 and receive your iPhone 5 golden color 32 I do not want to go back I want to machine used it, but

  • GUYS!! Is there any way to write BLOB's 4K using Oracle thin driver

    I've been trying for 3 days to do that but nothing worked ... Not setBinaryStream(x, new ByteArrayInputStream(anArrayWith10KBytes), anArrayWith10KBytes); nor setBytes(x, myArray), or setObject(x, myArray). Is there any way to store Blobs to Oracle 8.

  • Runtime Error Program: c:\programfile (x86)\Mozilla Firefox\firefox.exe

    Often when I am typing a private message on facebook and i have been typing for a while this "runtime error" happens and closes my program. The message that comes up is titled: Microsoft Visual C ++ Runtime library and in the body of the message it s

  • Connecting to Digital Camera - Problems

    When I connect the fifth gen ipod to the fujifilm digital camera it downloads the pictures with no problem, I copied 4 compact flash cards to the ipod. I then connected a Sony digital camera to the ipod it said it had finisheddownloading the pictures