Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use the destroy method?

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 :

  • What is this method used for?

I think it should do some cleaning on DOM objects (unbind events), but is there other cleaning to do?

  • Should this method be called on another event? Is it possible to detect when an object is destroyed and call this method at this time?

If anyone is interested in this framework, I posted it on gitHub, but right now there's no documentation :-/ : https://github.com/LeMisterV/EasyPrototype

like image 396
Nicolas Avatar asked Jun 29 '11 13:06

Nicolas


People also ask

What is the purpose of destroy?

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.

Can destroy () method be called inside the init () method?

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() .

What is destroy method in java?

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() .

What does client destroy do?

The destroy() method of the client object explicitly destroys that instance of the object and all its associated properties.


2 Answers

A better question, why do you need to destroy anything? if the window is unloading, everything will be garbage collected on your behalf.

like image 133
Joel Martinez Avatar answered Oct 04 '22 03:10

Joel Martinez


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.

like image 36
Jordan Avatar answered Oct 04 '22 04:10

Jordan