InterviewSolution
Saved Bookmarks
| 1. |
Which lifecycle hook plays a great role for memory leak not to occur? |
|
Answer» A memory leak occurs when memory is allocated for use and not deallocated where the memory area is no longer needed. It is caused by a PROGRAM that does not deallocate (free up) the extra memory allocated and FREQUENT memory leaks might halt everything.
Example: mounted() { this.chart = new PowerGraph(); }When the component is mounted the third-party library is created so it has to be destroyed in the beforeDestroy() lifecycle hook for memory leak not to occur as shown below. beforeDestroy() { this.chart.destroy(); }If the clean-up is not done before our component gets destroyed, then that memory is never going to be RELEASED. Hence, a memory leak occurs. |
|