File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Being more strict on Memory Leaks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Being more strict on Memory Leaks " Watch "Being more strict on Memory Leaks " New topic
Author

Being more strict on Memory Leaks

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I am sorry , i cant think any better heading for this question .

If we don't want to our Application to allow memory leaks ,then what is the best thing to do .

For example consider in a case of JDBC application :



Please share your ideas , what will be the good approach .


Save India From Corruption - Anna Hazare.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16058
    
  21

More like:


But a better solution would be to use something like the Spring Framework that wraps that stuff automatically. Less coding, less debugging, less chance someone will forget to do proper cleanup.

Incidentally, apps I've seen that were prone to leak memory very commonly did so precisely because they didn't have proper interception and cleanup of errors. Error-based leaks are slower to accumulate than most others, but sooner or later, they will add up.

And yest, you should close connections. If they're pooled connections and you don't close them, you won't only leak memory, you'll leak connections, and thereby eventually exhaust the connection pool. Which will bring you down a lot faster than memory leaks.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

If they're pooled connections and you don't close them, you won't only leak memory, you'll leak connections


Thank you for this .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Being more strict on Memory Leaks