DEV Community

[Comment from a deleted post]
Collapse
 
myogeshchavan97 profile image
Yogesh Chavan • Edited

While using this way also works, we should not un-necessarily return a function from another function as the inner function will remain in the memory occupying space even after the outer function has finished executing.

Collapse
 
nicorafales profile image
Nicolás Rafales • Edited

could you provide some feedback on this that demonstrates this is a memory leak?

What happens when we pass a "callback" to an Array.prototype.filter|map|reduce ?

What happens when we use libraries like lodash|lodash FP|Rambda and most of the frameworks we use that jump into callbacks from callbacks?

how do they handle those memory leaks? or do they not?

 
myogeshchavan97 profile image
Yogesh Chavan • Edited

You can check out this article to better understand how memory leak can happen when using closures. In filter, map or reduce we provide a callback function as an argument. We don't return a function from a function there.