-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex5.js
More file actions
38 lines (30 loc) · 996 Bytes
/
ex5.js
File metadata and controls
38 lines (30 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
/*
Problem:
Real leak detection is about *unexpected roots/retainers*, not whether an object exists.
Implement `identifyLeakPattern(snapshot)`.
Snapshot format (simplified, deterministic):
{
appRoots: [<id>, ...], // expected roots (e.g., request scope, live sessions)
leakRoots: [<id>, ...], // suspicious long-lived roots (e.g., global cache)
objects: [
{ id: 1, refs: [2, 3] },
{ id: 2, refs: [] }
]
}
Return:
- An array of object ids that are:
- reachable from leakRoots
- NOT reachable from appRoots
Interpretation:
These objects are being kept alive only because a suspicious root retains them.
Constraints:
- Deterministic graph traversal.
- Do not mutate the snapshot.
- Starter code is intentionally wrong (it ignores roots and returns everything).
*/
function identifyLeakPattern(snapshot) {
// TODO: implement graph traversal from roots
return snapshot.objects.map(o => o.id); // WRONG
}
module.exports = { identifyLeakPattern };