Manish
asked on
Memory Leakage , Out of Memory
Hi,
There is memory leakage in our application as it resuts into outofmemory exception after week time.
I want to
1.some practical examples to remove unwanted objects referece?
2.Some code examples.
3.IF this is my code
Public MySvc{
Map editors_=null;
private void myMethod(){
Map newEditors = Dao.getEditors();
editors = newEditors;
}
here newEditors will get GC or not? THis Svc class always active.
3.Some tools to find this memory leakage or out of memory.
Most helpful will be some code to understand me that here object will not get GC and here it will get GC.
}
There is memory leakage in our application as it resuts into outofmemory exception after week time.
I want to
1.some practical examples to remove unwanted objects referece?
2.Some code examples.
3.IF this is my code
Public MySvc{
Map editors_=null;
private void myMethod(){
Map newEditors = Dao.getEditors();
editors = newEditors;
}
here newEditors will get GC or not? THis Svc class always active.
3.Some tools to find this memory leakage or out of memory.
Most helpful will be some code to understand me that here object will not get GC and here it will get GC.
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your method:
private void myMethod()
{
Map newEditors = Dao.getEditors();
editors = newEditors;
}
After return from this method, 'newEditors' is certainly lost and the reference is virtually null.
But .... which other references still 'look at' that object.
Further: the worst problem with objects not garbage collected is those that you
'give' to handlers like those that you add as listeners.
Take care to .remove() everything you once .add() added.
;JOOP!
private void myMethod()
{
Map newEditors = Dao.getEditors();
editors = newEditors;
}
After return from this method, 'newEditors' is certainly lost and the reference is virtually null.
But .... which other references still 'look at' that object.
Further: the worst problem with objects not garbage collected is those that you
'give' to handlers like those that you add as listeners.
Take care to .remove() everything you once .add() added.
;JOOP!
ASKER
Still I am not clear abt this..
private void myMethod(){
Map newEditors = Dao.getEditors();
editors = newEditors;
//Should I write this or not?
newEditors=null;
//If I dont write code..newEditors=null ,is there memory leakage?
}
private void myMethod(){
Map newEditors = Dao.getEditors();
editors = newEditors;
//Should I write this or not?
newEditors=null;
//If I dont write code..newEditors=null ,is there memory leakage?
}
Map newEditors is local to the method, so it will go after return.
newEditors=null; is useless.
;JOOP!
newEditors=null; is useless.
;JOOP!
ASKER
So,
editors which is class level does not keep refrence to method level variable. in this case newEditors.
editors variable is always available when we locate this class.
Am I correct?
editors which is class level does not keep refrence to method level variable. in this case newEditors.
editors variable is always available when we locate this class.
Am I correct?
let's analys your code;
private Map = editors;
private void myMethod(){
Map newEditors = Dao.getEditors(); // memory allocates with Dao.getEditors() and reference by newEditors
editors = newEditors; // the same memory block will be referance by editors too
newEditors=null; //local referance null but the the memory block is still refered by editors so it will be stay in memory. so newEditors=null is useless.
}
>>editors which is class level does not keep refrence to method level variable. in this case newEditors.
infact it refers to Dao.getEditors()
>>editors variable is always available when we locate this class.
yes.
private Map = editors;
private void myMethod(){
Map newEditors = Dao.getEditors(); // memory allocates with Dao.getEditors() and reference by newEditors
editors = newEditors; // the same memory block will be referance by editors too
newEditors=null; //local referance null but the the memory block is still refered by editors so it will be stay in memory. so newEditors=null is useless.
}
>>editors which is class level does not keep refrence to method level variable. in this case newEditors.
infact it refers to Dao.getEditors()
>>editors variable is always available when we locate this class.
yes.
ASKER
Is anybody make this class such a way there will be memory leak?
So that I can understand it.
So that I can understand it.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you want to have a memory leak or do you want to get rid of one?
;JOOP!
;JOOP!
ASKER
There is memory leak in our application. I want to find that point.
I thing we have to use tools like vsnky suggessted OptimizeIt, JProbe, JInsight.
I dont know which one will be good...
if Anybody tell me best way to find that point..then i will follow that way.
I thing we have to use tools like vsnky suggessted OptimizeIt, JProbe, JInsight.
I dont know which one will be good...
if Anybody tell me best way to find that point..then i will follow that way.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another thing you might want to take a look at is JConsole. Also freely available with your JDK.
http://java.sun.com/developer/technicalArticles/J2SE/monitoring/
http://java.sun.com/developer/technicalArticles/J2SE/monitoring/
ASKER
I am using JProfiler but still not getting to catch it.
http://jb2works.com/memoryleak/index.html