1.

What is the purpose of destroying the functions and objects?(a) Consume unnecessary CPU cycles(b) Prevent the dropping of reference count to 0(c) Centralize the responsibility to clean up(d) All of the mentionedI have been asked this question in an interview for internship.This intriguing question originated from JavaScript and Memory Leak topic in portion Caching, Debugging and Animation of JavaScript

Answer»

The correct ANSWER is (d) All of the mentioned

Easy explanation: The primary purpose of a destroy FUNCTION is to centralize the responsibility for cleaning up anything that the object has done that will:

Prevent its reference count from dropping to 0 (for example, REMOVING problematic event listeners and callbacks and unregistering from any services).

Consume unnecessary CPU cycles, such as INTERVALS or ANIMATIONS.



Discussion

No Comment Found

Related InterviewSolutions