The Artima Developer Community
Sponsored Link

Java Answers Forum
Garbage Collection...

2 replies on 1 page. Most recent reply: May 10, 2004 3:43 AM by Sushil Srivastava

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Garbage Collection... Posted: Apr 22, 2004 4:57 PM
Reply to this message Reply
Advertisement
I have made a text editor and I am pretty sure there is a memory leak somewhere. I can't seem to find it.

The problem occurs when I edit a file and close it, it never gets garbage collected ie. finalize never gets called for the object responsible for the editing. If I just open a file and close it, the finalize method gets called.

Any clues?


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Garbage Collection... Posted: Apr 23, 2004 8:45 AM
Reply to this message Reply
You can't really depend on the finalize method getting called, so it isn't a safe place to release resources or do other necessary cleanup. As I understnd it, there there is no guarantee that the finalize method will ever be called, which make it next to useless. If you need to do some resource deallocation or other cleanup, then you should have some explicit close() or cleanup() method.

You can find some in-depth discussion of this topic in Bill Venners' articles on this site, in his book Inside the Java Virtual Machine and in Josh Bloch's book Effective Java.

Sushil Srivastava

Posts: 6
Nickname: sushilsri
Registered: May, 2004

Re: Garbage Collection... Posted: May 10, 2004 3:43 AM
Reply to this message Reply
Do the clean up in the finally pary of the try catch finally block. Cant depend on finalize part of the code or Garbage collector.

Flat View: This topic has 2 replies on 1 page
Topic: execute Unix commands Previous Topic   Next Topic Topic: Class path problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use