SwiftClipper icon indicating copy to clipboard operation
SwiftClipper copied to clipboard

Memory leak?

Open literalpie opened this issue 4 years ago • 5 comments

First, thank you so much for this library! It is exactly what I needed for a little project I've been working on.

I believe this library is causing a memory leak in my app. I use the "intersection" functionality pretty heavily, and memory usage goes up over time. Analysis with Instruments and other Xcode tools leaks me to think that there is a strong circular reference between OutPt types, as shown in this image: image

I believe I was able to eliminate the leak by making next and prev weak (but I did a lot of messy workarounds to prove that out - I probably broke other functionality in the process).

I believe TEdge has a similar issue: image

Please let me know if you need more information. I can put some time into trying to create a minimal repro if needed.

literalpie avatar May 09 '20 23:05 literalpie

Thanks a lot! I forgot releasing linked-list data like TEdge and OutPt after calculations. I will fix it in next commit.

lhuanyu avatar May 10 '20 04:05 lhuanyu

@lhuanyu Wow, thank you so much for the quick response and fix!

However, I believe there may still be an issue with OutPts being retained after a difference operation. For example, after running the following code, Xcode shows two OutPts being retained.

let path2 = [
    CGPoint(x: -5, y: 5),
    CGPoint(x: 20, y: 5),
    CGPoint(x: 20, y: -15),
    CGPoint(x: -5, y: -15)
]
let path3 = [
    CGPoint(x: 0, y: 5),
    CGPoint(x: 25, y: 5),
    CGPoint(x: 25, y: -15),
    CGPoint(x: 0, y: -15)
]
let differences = path2.difference(path3)
print(differences)

literalpie avatar May 12 '20 00:05 literalpie

OK. I will check it later.

lhuanyu avatar May 12 '20 08:05 lhuanyu

Hi there, @lhuanyu . I just wanted to check if you've had a chance to look into this issue? I know you may be busy with other things. This is just a friendly reminder since this issue has been closed, I don't want it to be forgotten.

literalpie avatar Jun 11 '20 22:06 literalpie

Sorry, I am very busy with my personal project recently. I have reopened this issue for later checking.

lhuanyu avatar Jun 12 '20 01:06 lhuanyu