I made a small javascript framework designed to add some useful stuff in the prototyped object model (super method call, inheritance, auto init...).
In this framework, some object methods are automatically called, like "init" to construct the object and "destroy" on window unload.
I have two questions about this destroy method :
I think it should do some cleaning on DOM objects (unbind events), but is there other cleaning to do?
If anyone is interested in this framework, I posted it on gitHub, but right now there's no documentation :-/ : https://github.com/LeMisterV/EasyPrototype
destroy() method is called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed.
You should not call the method yourself. The destroy() method just offers you the opportunity to execute some code upon shutdown. For example, to close some external resources which were opened during init() .
The destroy() method is used to stop the execution of thread groups and subgroups after the completion of the run() method, which executes without any cleanup. It can also cause deadlock during thread execution similar to suspend() .
The destroy() method of the client object explicitly destroys that instance of the object and all its associated properties.
A better question, why do you need to destroy anything? if the window is unloading, everything will be garbage collected on your behalf.
Some versions of Internet Explorer get stuck on circular references between JavaScript and the DOM, since they are garbage collected separately. This tends to be an issue when you start adding event handlers to everything.
What you should do in your framework is keep track of every time you add an event so that you can go through that array of events and destroy each of them on unload.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With