memory leak in useDrawCallback
See original GitHub issuerelated to #625
Any closure dependency of useDrawCallback lives forever. The draw callback function does appear to be garbage collected, however.
Steps to reproduce
this is the example code
export const SkiaGradientImp = ({
width,
height,
}: {
width: number;
height: number;
}) => {
const paint = Skia.Paint();
const onDraw = useDrawCallback((canvas) => {
// Cyan Circle
paint.setShader(
Skia.Shader.MakeLinearGradient(
Skia.Point(0, 0),
Skia.Point(width, height),
["red", "cyan", "lime"].map((color) => Skia.Color(color)),
null,
TileMode.Clamp
)
);
canvas.drawRect(Skia.XYWHRect(0, 0, width, height), paint);
});
return <SkiaView style={{ width, height }} onDraw={onDraw} />;
};
export const PerformanceGradients = () => {
const [index, setIndex] = useState(0);
return (
<TouchableWithoutFeedback onPress={() => setIndex((i) => i + 1)}>
<View style={{ flex: 1, flexDirection: "row", flexWrap: "wrap" }}>
{new Array(300).fill(0).map((_, i) => (
<SkiaGradientImp key={`${index}-${i}`} width={30} height={30} />
))}
</View>
</TouchableWithoutFeedback>
);
};
If you press the button, you will have 300 views in memory but 600 paints objects. If paint is not a closure dependency (we move it’s creation in the callback), it appears to be deleted properly.
In the case of the renderer, the dependencies to the closure are enormous et therefore the memory leak is much more obvious to notice.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Destroy Memory Leak — DataTables forums
I use the drawCallback function to do different customizations like setting colors and grouping on the rows, and this function is of course...
Read more >A memory leak when capturing callb… - Apple Developer
Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your...
Read more >java - How to avoid memory leaks in callback? - Stack Overflow
If the only references to an object are weak references, the garbage collector can reclaim the memory used by an object at any...
Read more >Memory leak - OWASP Foundation
Memory leak on the main website for The OWASP Foundation. ... intentionally trigger a memory leak, the attacker might be able to launch...
Read more >Finding Memory Leak in Go Service - Nylas
Here at Nylas, we have a process to diagnose memory leak for Go services. Tools such as pprof and minikube can help us...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sent!
(Just a small note, running on device (iOS) does not show any signs of memory leaks either.)