user3522366
user3522366

Reputation: 1

memory leak issue in code

I am working on an application & my code is having out of memory error. I am not able to see memory utilisation of the code.so I am very confused were to see.

Also after my little analysis I came to kow that there is private static object getting creating & in the constructor of that class. some more objects are getting created. & that class is multithreaded..

so I want to know since the static objects does not get garbage collected.. will all the objects related to the constructor will not be garbage collected??

Upvotes: 0

Views: 62

Answers (3)

Niels Bech Nielsen
Niels Bech Nielsen

Reputation: 4859

You say you are not capable of seeing the memory utilisation?

Have you tried using JVisualVM (in $JAVA_HOME/bin/jvisualvm) It should be capable of attaching to local processes and take heap dumps.

Also, Eclipse Memory Analyzer has some good reports for subsequent analysis

Upvotes: 0

shemerk
shemerk

Reputation: 387

You might not have a memory leak - you might simply surpassed the amount of avaialble RAM your system can provide. you can add several JVM arguments to limit the size of RAM allocated to your runtime enviorment, and control the garbage collector - the tradeoff is it usually consumes more CPU.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533442

A static reference is only collected when the class is unloaded, and this only happened when the class loader is not used any more. If you haven't got multiple class loaders it is likely this will never be unloaded (until your program stops)

However, just because an object was once referenced statically doesn't change how it is collected. If you had a static reference to an object and no longer have a reference to that object, it will be collected as normal.

Having multiple threads can make finding bugs harder, but it doesn't change how objects are collected either.

You need to take a memory dump of your application and see why memory is building up. It is possible the objects you retaining are all needed. In this case you need to

  • reduce your memory requirement
  • increase your maximum memory.

Upvotes: 1

Related Questions