Most Skija classes (extending RefCnt or Managed) are backed by native C++ pointers.
Automatic Management: Skija automatically frees C++ structures when the corresponding Java objects are collected by the Garbage Collector (GC). This makes Skija safe to use by default.
Manual Management: All Managed descendants implement AutoCloseable. To free memory more aggressively (e.g., for short-lived objects), use a try-with-resources block. This is not mandatory but can help reduce memory pressure.
Warning: Once a resource is closed via AutoCloseable, it can no longer be used.
// Automatic management (safe, but relies on GC)
void drawCircle(Canvas c) {
Paint p = new Paint();
c.drawCircle(0, 0, 10, p);
}
// Manual management (immediate cleanup)
void drawCircle(Canvas c) {
try (Paint p = new Paint()) {
c.drawCircle(0, 0, 10, p);
} // p is freed here
}