angular - Is there any destroy hook for pipes in angular2 (same as for components)? -
after investigating several days(!?!) huge memory leakage of current angular2 application, came new discovery:
apparently, async pipe, heavily used throughout application, subscribing observable, never released (unsubscribed) when component , pipes cleaned-up.
it accumulated number of ~11,000 observers single observable few user actions (which caused app crash).
i need unsubscribe observable, , in order need hook destruction, similar ngondestroy, pipes.
is there such hook, or if not, how suggest unsubscribe?
if take @ async pipe code, can see using ngondestroy
how in directive.
snippet asyncpipe
code:
@pipe({name: 'async', pure: false}) @injectable() export class asyncpipe implements ondestroy { ... ngondestroy(): void { if (ispresent(this._subscription)) { this._dispose(); } } ... }
the key using: pure:false
,
from ondestroy
to create stateful pipe, should implement interface , set pure parameter false in pipemetadata.
a stateful pipe may produce different output, given same input. stateful pipe may contain state should cleaned when binding destroyed. example, subscription stream of data may need disposed, or interval may need cleared.