+ 10
No destructor in Java? What is the best way to create destructors in java
I know about Garbage collector in java but I want other way
10 Answers
+ 7
thanks for your answer Mert Yazıcı
I want to make own đ€destructors
+ 5
I want to force I want create own destroctor in java
+ 4
no need it will destroy object implicitly
+ 3
u guys do not understanding my question
+ 3
I'm understanding your question and my answer is: Do not write code, that requires destructor.
There's a notification about destruction of object, that is performed just before the object is deleted. Unfortunately you can't control the moment and thread of this notification. It means, that socket, that is closing in such notification, will not be closed until garbage collector process it and will use related resources all that time. You can run collector manually, but it not guarantee that all released objects will be destroyed. So, don't use destructors in Java if you don't want to spend a lot of time in the debugging of random errors.
+ 3
of course as a coder there are levels you go through. while we all need to get to the point of avoiding code that needs destruction, you must for now know that it can clean itself Iver time and you may not need to force code to delete.
+ 2
Java has a built in GC.
+ 1
The best way is to not use destructor in Java. You have to complete operation directly, like socket.close(), if you need release resources, or just throw objects in other case.
+ 1
Memory management in Java is specific to it
A garbage collector runs and free object which has no left owner
So if you want to save memory, try to reuse those object