When should the destroy method be used?

I made a small javascript infrastructure designed to add some useful material to a prototyped object model (calling a super method, inheritance, auto init ...).

In this structure, some object methods automatically call, for example, "init" to create the object and "destroy" when the window is unloaded.

I have two questions about this destruction method:

  • What is this method used for?

I think it should do some cleanup on DOM objects (unbind events), but is there another cleanup?

  • 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 structure, I posted it on gitHub, but right now there is no documentation: - /: https://github.com/LeMisterV/EasyPrototype

+5
source share
3 answers

The best question is: why do you need to destroy something? if the window is unloaded, everything will be garbage collected on your behalf.

+3
source

Some versions of Internet Explorer are stuck in round links between JavaScript and the DOM, as they are collected separately from the garbage. This is usually a problem when you start adding event handlers to everything.

, , , .

+2

, "" ( ) , "" ​​ . ( ) Garbage Collection.

, , ( "destroy" ), - , , .

+1

All Articles