I have an angular component and inside ngOnDestroy hook I want to add asynchronous function that makes http call to delete something for example. I wonder how is memory managed and what is the scope of the callback function ? If garbage collector decides to release memory by reference does it mean that the component will stay in memory until the delete callback is complete ? Here is a stackblitz demo and examples of what I'm testing.
First:
ngOnDestroy() {
this.http.delete(...)
}
Since I didnt provide .then(...) callback does it mean component can be completely unloaded from memory ?
Second:
async ngOnDestroy() {
await this.http.delete(...)
}
Why does component get destroyed and doesn't await for the delete() to complete ?
Third:
ngOnDestroy() {
this.http.delete(...).then(console.log);
}
Since I provided callback function does it mean component will stay in memory until the callback func completes ?
How can I see what's happening in memory allocation ? Is there a way to see what garbage collector does or maybe specify a callback function when certain object is released from memory ? Thanks
EDIT
Based on this Memory Management MDN article it appears that since 2012 Reference-counting algorithm has been replaced by Mark-and-sweep and I could expose garbage collector if I run my ng serve node process with --expose-gc flag