File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory loss

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we improve memory loss in our code.?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper beaten me nicely
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
infinite loop ? its evil. you should rewrite your code then.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:infinite loop ? its evil. you should rewrite your code then.


OHK
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aye Aye SIR
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic