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

[SR-9493] NSAttributedString Leaks #3574

Open
swift-ci opened this issue Dec 12, 2018 · 9 comments
Open

[SR-9493] NSAttributedString Leaks #3574

swift-ci opened this issue Dec 12, 2018 · 9 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-9493
Radar rdar://46674511
Original Reporter Mahdi.Makhdumi (JIRA User)
Type Bug

Attachment: Download

Environment

macOS High Sierra 10.13.6

Xcode version 10.1

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Leak
Assignee None
Priority Medium

md5: 2d60476a48e451a1c7db0c786d26aab1

Issue Description:

I'm trying to convert html to string using NSAttributedString, everything works fine, but I found that using this initializer causes a leaks in memory.

init(data: Data, options: [NSAttributedString.DocumentReadingOptionKey : Any] = [:], documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) throws 

What I've tried at first:

let data = "<p>test</p>".data(using: .utf8)!
 _ = try! NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)

Result:

after doing some research, I taught maybe autoreleasepool can fix it, so I've tried again:

autoreleasepool{
    let data = "<p>test</p>".data(using: .utf8)!
    for _ in 1...1000 {
        _ = try! NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
    }
}

Result: again I got leaks.

@swift-ci
Copy link
Contributor Author

Comment by Mahdi Makhdumi (JIRA)

also tested:
let data = "<p>test</p>".data(using: .utf8)!
autoreleasepool {
    _ = try! NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
}

@belkadan
Copy link

You're supposed to put the autorelease pool inside the loop, but even so.

@swift-ci
Copy link
Contributor Author

Comment by Mahdi Makhdumi (JIRA)

yeah it's the loop body, got leaks anyway.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
@mohamedfarid1993
Copy link

Hey, Is there a solution for this ?

@dxshindeo
Copy link

Waiting for solution as well. This breaks the purpose of instrumentation.

@rahulkhatrirws
Copy link

Its been 4 years. No solution yet?

@jaikrishna-zuper
Copy link

Any workaround or solutions to fix the memory leak

@andestaerfan
Copy link

Any workaround?

@VeretennikovSV
Copy link

Is there any solution?

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

No branches or pull requests

8 participants