Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Disable .step by default to fix memory leak #2
By default, Chainsaw retains a history of all actions including all arguments. In some cases where Chainsaw objects are long-lived, such as node-binary, this causes a memory leak.
This patch changes Chainsaw such that no history of actions is kept by default. Instead, the history is enabled automatically as soon as the user calls a function (such as trap, down or jump) that requires it.
This patch should maintain downwards compatibility and should benefit most code using chainsaw without any changes. Tested with node-binary.
Note that two unit tests fail - those were also failing before this patch.
I can't confirm the purported test behavior:
Ok, what's happening is that my little automatic upgrade trick cannot work retroactively. node-chainsaw no longer keeps a history of actions by default, so when the jump() call comes, we've already forgotten about the first call to x().
This poses a bit of a dilemma: I still think we must get rid of the history of actions for any use case where a Chainsaw may be long-lived (such as node-binary). At the same time we still want to support .jump() for those that use it. But because we can't see into the future, I don't think we can decide that purely with behind-the-scenes magic now.
Suggestion 1: We can make the upgrade mechanism explicit. If one wishes to use .jump(), one must first call (a new function) .record() to start recording actions. That requires libraries using .jump() to upgrade, but it fixes the memory issue for all others transparently.
Suggestion 2: We can keep the default behavior and add a new subconstructor Chainsaw.light(). Any module that doesn't use jump() (like node-binary) could switch to the new constructor to get a version of Chainsaw that does not retain a history.
With option no 1 there is no "trap" for new users of Chainsaw to accidentally leak memory.