I'm trying to get a better understanding of ionic2
and ionic3
.
How does the Garbage Collection work in ionic?
Like seen in this picture (source):
Some of the memory gets G.C'd when going to a new page. However the memory is still significantly higher than before any video had been played.
OK I'm gonna give this one a try:
ngOnDestroy()
. Why is this method important to you as an app developer? Because it gives you the chance to clean up behind yourself. This method is called just before your component is destroyed, what does that mean? You do not need your allocated objects, arrays, video-elements (set src=''
and then call load()
), etc. anymore and you can release the memory. This and this are good reads on how to free memory. However as the docs for onDestory()
mention you only have to release memory that is not cleaned up by the automic GC (subscriptions, media-elements, ...). Which brings us to the next level:delete
keyword. The following image visualizes the mark and sweep process:Image taken from this article, it explains how javascript memory management works in very great detail, I strongly recommend reading it.
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