I am using the new Angular feature named signals like this:
arr: WritableSignal<string[]> = signal([]);
I want to know if this signal is destroyed from browser memory after the component is destroyed, because this array can get quite big and maybe will be constructed and destroyed several times.
MihailJordan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If the signal is inside a component, then the contents of the component will get destroyed, so yes, the signal also is destroyed.
I think it will be destroyed but will stay in memory, until garbage collection runs in the browser to remove it permanently.
If the signal is in a service then its to totally different.
With providedIn: ‘root’ -> The service exists at the root of the application, so its never destroyed, unless you refresh the page.
Without providedIn: ‘root’ -> will get destroyed when the module/component which has the service in the providers array, get’s destroyed.