|
|
|
|
|
by nknighthb
4733 days ago
|
|
You seem to be describing behavior that the article did not. Specifically, the retention of 'str' because of the 'logIt' function. If you read more closely, you'll notice that logIt was not the cause of 'str's retention, but instead, the doSomethingWithStr function was. When logIt is present by itself, str is not retained. Only when doSomethingWithStr is added alongside logIt is str retained. |
|
First, you are correct that I specifically mentioned the logIf function when I discuss the specific example.But that does not take away from my thorough explanation of the main reason for the problem. In fact, everything I said about the logIt function applies to the doSomethingWithStr function, since they are both closures, so my explanation stands as is.
If you read my explanation again, you will see that I clearly explained that closures still have access to the outer function's scope, so both the logIt and the doSomethingWithStr functions have access to the outer function's scope chain even after the outer function or any of the other closures returns.
It is not until both all closures are destroyed or returns that the outer function's scope activation object is destroyed.