-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(🐛): memory leak with CPU surfaces on Node/Web (#2327)
- Loading branch information
1 parent
4e63f30
commit 8253845
Showing
10 changed files
with
116 additions
and
17 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,43 @@ | ||
import React from "react"; | ||
|
||
import { Circle, Group } from "../components"; | ||
import { processResult } from "../../__tests__/setup"; | ||
import { setupSkia } from "../../skia/__tests__/setup"; | ||
|
||
import { drawOnNode } from "./setup"; | ||
|
||
describe("Surface", () => { | ||
it("A raster surface shouldn't leak (1)", () => { | ||
const { Skia } = setupSkia(); | ||
// When leaking, the WASM memory limit will be reached quite quickly | ||
// causing the test to fail | ||
for (let i = 0; i < 500; i++) { | ||
const surface = Skia.Surface.Make(1920, 1080)!; | ||
const canvas = surface.getCanvas(); | ||
canvas.clear(Skia.Color("cyan")); | ||
surface.flush(); | ||
const image = surface.makeImageSnapshot(); | ||
image.dispose(); | ||
surface.dispose(); | ||
} | ||
}); | ||
it("A raster surface shouldn't leak (2)", () => { | ||
for (let i = 0; i < 1000; i++) { | ||
//const t = performance.now(); | ||
const r = 128; | ||
const surface = drawOnNode( | ||
<> | ||
<Group blendMode="multiply"> | ||
<Circle cx={r} cy={r} r={r} color="cyan" /> | ||
<Circle cx={r} cy={r} r={r} color="magenta" /> | ||
<Circle cx={r} cy={r} r={r} color="yellow" /> | ||
</Group> | ||
</> | ||
); | ||
surface.flush(); | ||
//console.log(`Iteration ${i} took ${Math.floor(performance.now() - t)}ms`); | ||
processResult(surface, "snapshots/leak.png"); | ||
surface.dispose(); | ||
} | ||
}); | ||
}); |
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
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