| Author |
Memory loss
|
Kaustubh G Sharma
Ranch Hand
Joined: May 13, 2010
Posts: 1145
|
|
|
How can we improve memory loss in our code.?
|
No Kaustubh No Fun, Know Kaustubh Know Fun..
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
I guess you're asking about memory leaks.
It's hard to create memory leaks in Java, because Java has automatic memory management (garbage collection). There are ways to have memory leaks, but this will only happen if you keep references to objects that you don't need anymore.
Normally memory leaks are not a big problem in Java applications. If you think you have a memory leak, you should use a profiler to monitor the application and find out what the source of the leak is.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
I think you are taking about prevention of memory leak? you no need to worry about it, Java takes care for you. though in some situation you need to code properly such a way that no reference are pointed the obsolete objects.
for example: when you shrink an array , make sure that (removed)references are assigned to a null value.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Jesper beaten me nicely
|
 |
Kaustubh G Sharma
Ranch Hand
Joined: May 13, 2010
Posts: 1145
|
|
|
like we if we stuck is some very big infinite loop in such case can we avoid it if it occurs ?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
infinite loop ? its evil. you should rewrite your code then.
|
 |
Kaustubh G Sharma
Ranch Hand
Joined: May 13, 2010
Posts: 1145
|
|
Seetharaman Venkatasamy wrote:infinite loop ? its evil. you should rewrite your code then. 
OHK
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
|
|
|
It sounds like there you're talking about memory use, not memory loss. Yes, it's possible to run out of memory if you use too many resources - e.g. by creating lots of objects that are all still in scope at the same time. If you're in a big loop and creating objects that are only in scope within the loop, though, the garbage collector will be able to clean them out when it needs to.
|
 |
Kaustubh G Sharma
Ranch Hand
Joined: May 13, 2010
Posts: 1145
|
|
Q: On server side validation if you've any exception how you going to handle it (Want some solution regarding struts) and which part you're going to see(He mentioned that let it be your DAO)
A.After giving all general answers(As I don't know the main one) I also check memory leaks..
Q. How you recover your memory leaks ? (Put the infinite loop in front of me)
A. Don't know
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
Kaustubh G Sharma wrote:
Q. How you recover your memory leaks ? (Put the infinite loop in front of me)
A. Don't know
In Java, for most intents and purposes, a memory leak is defined as keeping unwanted objects reachable. This, of course, means that it is a bug, as why would you ever want to do that?
So to recover from memory leaks doesn't make sense. Just fix the bug so the memory leak is gone. To keep unwanted objects around, and then "recover" the memory when needed serves what purpose?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Kaustubh G Sharma
Ranch Hand
Joined: May 13, 2010
Posts: 1145
|
|
Aye Aye SIR
|
 |
 |
|
|
subject: Memory loss
|
|
|