Commit 114c62b9 authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Fix memory leak with ScriptedIdleTaskController

If there is an untriggered idle task when the document is gone, it
introduces memory leak because IdleRequestCallbackWrapper keeps a
reference to the ScriptedIdleTaskController, making it live longer
than the document.

This patch fixes the issue by letting IdleRequestCallbackWrapper
store a WeakPersistent instead.

BUG=595155

Review-Url: https://codereview.chromium.org/2618893002
Cr-Commit-Position: refs/heads/master@{#441929}
parent c771336b
<!doctype html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
test(
() => requestIdleCallback(() =>
assert_unreached('Should not trigger the idle task during the test.')),
'Untriggered idle task does not introduce memory leak.');
test(
() => {
const handle = requestIdleCallback(() =>
assert_unreached('Should not trigger the idle task during the test.'));
cancelIdleCallback(handle);
}, 'Canceled idle task does not introduce memory leak.');
</script>
......@@ -62,7 +62,7 @@ class IdleRequestCallbackWrapper
: m_id(id), m_controller(controller) {}
ScriptedIdleTaskController::CallbackId m_id;
Persistent<ScriptedIdleTaskController> m_controller;
WeakPersistent<ScriptedIdleTaskController> m_controller;
};
} // namespace internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment