You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i want to implement a 'long stack trace' using async hooks like this:
store stack in a map when async resource's initiated
restore the stack in 'before' callback.
how can i delete the stack in the map?
(not using weakmap,because
Note: In some cases the resource object is reused for performance reasons, it is thus not safe to use it as a key in a WeakMap or add properties to it.
In terms of destroy your implementation is fine. You are right that the promises aren't immediately destroyed and thus the stack traces are also not immediately destroyed. However, this is fine, what is important is that they are eventually destroyed, otherwise you have a memory leak.
PS: You should be aware that before and after can be called multiple times in the same tick. (e.g. before(1), before(2), after(2), after(1)), thus global.longStack should be a stack and not a single value.
PS: You should be aware that before and after can be called multiple times in the same tick. (e.g. before(1), before(2), after(2), after(1)), thus global.longStack should be a stack and not a single value.
i've inspected your implementation and gained much.
However,when i use your implementation to test
i got the same result: after half an hour,the traces map in your implementation still has 'the Promise' stack. If the site is busy(more and more requests come),then the 'traces' will eat more and more memeroy
thanks @AndreasMadsen
i've confirmed that promise is eventually destroyed.
If it's not destroyed(maybe a long time,several hours,or several days),it's really ok.
The reason is:
promises not to many,GC think it's not time to trigger a collection(expensive)
when there're to many,GC will trigger collection(you can make new more promises to verify this)
Activity
AndreasMadsen commentedon Jul 24, 2017
Promises are only destroyed by the V8 garbage collector. If you give the process some time it should eventually destroy them.
Fishrock123 commentedon Jul 24, 2017
Yes, exactly what @AndreasMadsen said.
(Generally avoid holding onto any resource of handle for an indeterminate amount of time.)
wengeezhang commentedon Jul 25, 2017
i want to implement a 'long stack trace' using async hooks like this:
store stack in a map when async resource's initiated
restore the stack in 'before' callback.
how can i delete the stack in the map?
(not using weakmap,because
in nodejs api doc)
@Fishrock123
AndreasMadsen commentedon Jul 25, 2017
In terms of
destroyyour implementation is fine. You are right that the promises aren't immediately destroyed and thus the stack traces are also not immediately destroyed. However, this is fine, what is important is that they are eventually destroyed, otherwise you have a memory leak.PS: You should be aware that before and after can be called multiple times in the same tick. (e.g.
before(1), before(2), after(2), after(1)), thusglobal.longStackshould be a stack and not a single value.You can look at my long stack trace (https://github.com/AndreasMadsen/trace/blob/master/trace.js) for more inspiration.
wengeezhang commentedon Jul 25, 2017
@AndreasMadsen Thanks for your info:
i've inspected your implementation and gained much.
However,when i use your implementation to test
i got the same result:
after half an hour,the traces map in your implementation still has 'the Promise' stack. If the site is busy(more and more requests come),then the 'traces' will eat more and more memeroy
wengeezhang commentedon Aug 17, 2017
my worries in this issue do not exist!!!
thanks @AndreasMadsen
i've confirmed that promise is eventually destroyed.
If it's not destroyed(maybe a long time,several hours,or several days),it's really ok.
The reason is:
async_hooks: remove promise object from resource