+ 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

3rd Sep 2018, 8:10 AM
Charan Leo25
Charan Leo25 - avatar
10 Antworten
+ 7
thanks for your answer Mert Yazıcı I want to make own 🤔destructors
3rd Sep 2018, 8:18 AM
Charan Leo25
Charan Leo25 - avatar
+ 5
I want to force I want create own destroctor in java
5th Sep 2018, 6:57 AM
Charan Leo25
Charan Leo25 - avatar
+ 4
no need it will destroy object implicitly
3rd Sep 2018, 12:31 PM
Aarav Raj
Aarav Raj - avatar
+ 3
u guys do not understanding my question
3rd Sep 2018, 12:57 PM
Charan Leo25
Charan Leo25 - avatar
+ 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.
3rd Sep 2018, 7:15 PM
Sergey Ushakov
Sergey Ushakov - avatar
+ 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.
5th Sep 2018, 6:55 AM
lufafa noah
lufafa noah - avatar
+ 2
Java has a built in GC.
5th Aug 2019, 12:27 AM
Sonic
Sonic - avatar
+ 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.
3rd Sep 2018, 10:28 AM
Sergey Ushakov
Sergey Ushakov - avatar
+ 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
21st Jan 2019, 11:32 PM
Abel Louis
Abel Louis - avatar