Skip to content

Commit

Permalink
fix Spark memory leak (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Jun 25, 2013
1 parent 972e295 commit 49e9813
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/spark/spark.js
Expand Up @@ -1205,6 +1205,21 @@ Spark.createLandmark = function (options, htmlFunc) {

landmark._range = range;
renderer.landmarkRanges.push(range);
// Help GC avoid an actual memory leak (#1157) by nulling the
// `renderer` local variable, which holds data structures about
// the preservation and patching performed during this rendering
// pass, including references to the old LiveRanges. If
// `renderer` is retained by the LiveRange we initialize here,
// it creates a chain linking the new LiveRanges to the
// renderer, to the old LiveRanges, to the old renderer, etc.
//
// The reason the new LiveRange might retains `renderer` has to
// do with how V8 implements closures. V8 considers
// `range.finalize` to close over `renderer`, even though it
// doesn't use it. Because `renderer` is used by *some* nested
// closure, it apparently is retained by all nested closures as
// part of `Spark.createLandmark`'s function context.
renderer = null;
});
};

Expand Down

5 comments on commit 49e9813

@frozeman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pablo-zocdoc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍔

@crapthings
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't wait lalala

@evandrix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asinglebit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.