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-14877] JSON Decoder seems to be leaking / not releasing memory #57224

Open
swift-ci opened this issue Jul 5, 2021 · 1 comment
Open

[SR-14877] JSON Decoder seems to be leaking / not releasing memory #57224

swift-ci opened this issue Jul 5, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 5, 2021

Previous ID SR-14877
Radar rdar://problem/80238316
Original Reporter danielhall (JIRA User)
Type Bug

Attachment: Download

Environment

macOS 11.3.1
Xcode 12.5
iPhone 12 simulator or iPhone 11 Pro on iOS 14.4.2

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 5c9b80d9f3cb8dc5b6e9fed91dddde73

Issue Description:

I have the attached large JSON file. I have declared this struct to decode an array of from the JSON:

struct Symbol: Codable {
{{ let symbol: String}}
{{ let name: String}}
{{ let type: String}}
{{ let exchange: String}}
}

If I decode as follows:

var symbols = try? JSONDecoder().decode([Symbol].self, from: Data(contentsOf: Bundle.main.url(forResource: "symbols", withExtension: "json")!)

and then later set symbols to nil:

symbols = nil

there is still quite a bit of memory (several MB) that is still allocated and not released. I've isolated this memory consumption to JSONDecoder (not Data or other types) in the example above, and as far as I can tell the memory is never released for the remaining lifetime of the app session.

As a related note: If you search the web for "Swift JSON Decoder memory leak" you will find several threads on Stack Overflow, Apple Developer Forums, etc. where this problem is raised and remains unresolved.
@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants