-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed memory leak in internal actor registry
- Loading branch information
Showing
3 changed files
with
18 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'xstate': patch | ||
--- | ||
|
||
Fixed memory leak - each created service has been registered in internal map but it was never removed from it. Registration has been moved to a point where Interpreter is being started and it's deregistered when it is being stopped. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { Actor } from './Actor'; | ||
|
||
const children = new Map<string, Actor>(); | ||
const idMap = new Map<Actor, string>(); | ||
|
||
let sessionIdIndex = 0; | ||
|
||
export interface Registry { | ||
register(actor: Actor): string; | ||
bookId(): string; | ||
register(id: string, actor: Actor): string; | ||
get(id: string): Actor | undefined; | ||
lookup(actor: Actor): string | undefined; | ||
free(id: string): void; | ||
} | ||
|
||
export const registry: Registry = { | ||
register(actor) { | ||
const id = `x:${sessionIdIndex++}`; | ||
bookId() { | ||
return `x:${sessionIdIndex++}`; | ||
}, | ||
register(id, actor) { | ||
children.set(id, actor); | ||
idMap.set(actor, id); | ||
|
||
return id; | ||
}, | ||
get(id) { | ||
return children.get(id); | ||
}, | ||
lookup(actorRef) { | ||
return idMap.get(actorRef); | ||
free(id) { | ||
children.delete(id); | ||
} | ||
}; |