Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RNSVGRenderable.m #1439

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

swittk
Copy link

@swittk swittk commented Aug 15, 2020

Fixed memory leak when calling CGPathCreateCopyByTransformingPath (it's never released)

Summary

Explain the motivation for making this change: here are some points to help you:

  • What issues does the pull request solve? Please tag them so that they will get automatically closed once the PR is merged
    Memory leak on Path with vector effect non-scaling-stroke #1436

  • What is the feature? (if applicable)
    Fixed memory leak

  • How did you implement the solution?
    Added CFAutoRelease to the temporary path object

  • What areas of the library does it impact?
    Rendering vectorEffect="nonScalingStroke"

Test Plan

Render this

<Path d={someData} strokeWidth={2} stroke="black" strokeLinecap="round" vectorEffect="nonScalingStroke"  />

What's required for testing (prerequisites)?

React native

Show memory debugger when running the code as above

Compatibility

This only affects iOS

Checklist

  • I have tested this on a device and a simulator
  • I added documentation in README.md
  • I updated the typed files (typescript)
  • I added a test for the API in the __tests__ folder

Fixed memory leak when calling CGPathCreateCopyByTransformingPath (it's never released)
@guiccbr
Copy link

guiccbr commented Aug 16, 2022

@swittk , @WoLewicki, can we merge this? This is significantly impacting performance. I have a patch-package in my repo with a slightly modified version of that code:

     if (_vectorEffect == kRNSVGVectorEffectNonScalingStroke) {
-        path = CGPathCreateCopyByTransformingPath(path, &svgToClientTransform);
+        CGPathRef newPath = CGPathCreateCopyByTransformingPath(path, &svgToClientTransform);
+        if (newPath) {
+            path = CFAutorelease(newPath);
+        }
         CGContextConcatCTM(context, CGAffineTransformInvert(svgToClientTransform));
     }

Needed to add the conditional if (newPath) to make sure that the path is null checked before calling CFAutorelease.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants