0

I've been searching code for the finalize for nearly 1 mon. Can u pls help me for the code. Thanks in advance.

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
Pavalesh
  • 247
  • 2
  • 4
  • 12
  • 3
    I'm voting to close your question because it isn't posed clearly enough to garner any answers. Please edit your question and elaborate on what you're looking for. – Mark Elliot Jul 07 '10 at 01:24
  • I'm voting to reopen this question because I searched for the code contained in both answers on the site, and this question was the first result. I recreated the subject line to match what the answers clearly felt was the question. Also, +1. – Erick Robertson Mar 27 '11 at 11:57

2 Answers2

2

finalize

protected void finalize() throws Throwable
{
    try
    {
        //close unmanaged resources
    } finally {
        super.finalize();
    }
}

Note that outside of unmanaged resources, you shouldn't ever be doing this..

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • +1 I'm currently doing this because I want to see in my log verification that a certain class is being cleaned up. I suppose that's "outside of unmanaged resources", but I find that phrase a bit obfuscated. Maybe it's the hidden double negative. Maybe it's that I would never use anything big enough to be tarred with the epithet "Resource Management". – Erick Robertson Mar 27 '11 at 12:07
2
protected void finalize() throws Throwable {
    try {
        close();        // close open files
    } finally {
        super.finalize();
    }
}

You call super.finalize() in the finally block.

Source

zengr
  • 38,346
  • 37
  • 130
  • 192
  • 1
    Looks like we both googled the same link - find it hard to believe that a month's worth of googling wouldn't start with [this](http://www.google.com/search?q=java+finalize) – BlueRaja - Danny Pflughoeft Jul 07 '10 at 01:28
  • My first search brought me right here. I remembered the proper declaration for this method throwing something, and wanted to see it. Of course, I did my first search on SO. – Erick Robertson Mar 27 '11 at 12:02