FRESHERSHOME![]() |
This is a discussion on can any one tell me the basic difference b/w destructor in c,c++ &finalizer in java? within the JAVA forums, part of the Languages category; computer programming...
| |||||||
| Notices |
| JAVA JAVA Discussion Forum, Jave Related help |
![]() |
| | Thread Tools | Display Modes |
|
#1
| |||
| |||
| computer programming
__________________ Powered by Yahoo! |
|
#2
| |||
| |||
| Destructors don't exist in C, just in C++. I believe you need destructors in C++ to do things like deallocate memory for arrays your objects generated dynamically. In Java, all your memory gets deallocated automatically when you stop using it. You use finalizers to stop using system resources, like file streams and network sockets. There are usually better ways to do this (like closing a stream in the finally clause of the try-catch block the stream is used in). Only use finalizers when necessary. I don't think you're supposed to use C++ destructors to stop using system resources, but you probably could if you wanted to.
__________________ Powered by Yahoo! |
|
#3
| |||
| |||
| destructor in c/ c++ As opposed to a constructor, a destructor is called when a program has finished using an instance of an object. A destructor does the cleaning behind the scenes. Like the default constructor, the compiler always create a default destructor if you don't create one. Like the default constructor, a destructor also has the same name as its object. This time, the name of the destructor starts with a tilde. and in destructor in Java the finalize() method is called before the object is to gced. Note that the invocation of finalize is not gantenteed to be called at any paticular time. And may not be called if System.exit(int) is invoked before the object is gced. If you want an operation to peform on exit use Runtime.addShutdownHook method. If you want to add a destructor to an existing object that you are not implementing you can use a PhantomReference to get notified when the object is dead. To add a destructor use: protected void finalize() throws Throwable { //do finalization here super.finalize(); //not necessary if extending Object. }
__________________ Powered by Yahoo! |
![]() |
| Tags |
| tell, basic, difference, destructor, finalizer, java |
| Thread Tools | |
| Display Modes | |
|
|
Sitemap
Jobs by Location: Advertising and Marketing Jobs - IT Software Jobs - Walk-in Jobs - BPO Jobs - Government Jobs - Sales / BD Jobs - Tele Communication Jobs App Programming - Network Admin
Jobs By Location: Jobs in Bangalore - Jobs In India - Jobs in Delhi - Jobs in Hyderabad - Jobs in Kochi - Jobs in Mumbai - Jobs in Trivandrum - Jobs in pune - Jobs in Jonida - Jobs in Chennai - Jobs in Coimbator
Jobs Type: Full Time Jobs - Part Time Jobs
Latest Jobs - Accounting Jobs - Engineering Jobs - IT Jobs - Walkins - How to Face Interview - HR Round Tips - Career Info - Guide For Freshers - Apply for Jobs - Future Studies - Jobs Forums - Freshers IT Software Salary Details