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

try PMJSON.JSON.decode leaks #30

Closed
iDevPro opened this issue Jan 14, 2019 · 8 comments
Closed

try PMJSON.JSON.decode leaks #30

iDevPro opened this issue Jan 14, 2019 · 8 comments

Comments

@iDevPro
Copy link

iDevPro commented Jan 14, 2019

Hello, I found many memory leaks if I use try PMJSON.JSON.decode(jsonData)
scalars.append(c) caused issue in function:
private mutating func parseValue(_ c: UnicodeScalar) throws -> JSONEvent

@lilyball
Copy link
Collaborator

What makes you think this leaks?

@lilyball
Copy link
Collaborator

More generally, if you're seeing leaks in your app, and the allocation for the leaks is being traced to PMJSON, almost certain what's happening is you're leaking the resulting JSON values that you decoded using PMJSON rather than PMJSON itself is leaking anything.

@iDevPro
Copy link
Author

iDevPro commented Jan 15, 2019

More generally, if you're seeing leaks in your app, and the allocation for the leaks is being traced to PMJSON, almost certain what's happening is you're leaking the resulting JSON values that you decoded using PMJSON rather than PMJSON itself is leaking anything.

Hmm, in all PMJSON.JSON.decode calls ?)

@lilyball
Copy link
Collaborator

@iDevPro JSON.decode will allocate memory. If this memory is subsequently leaked, that does not mean PMJSON is the one leaking it, that just means the memory was allocated there. You need to look at the retain/release history for the String object that owns this memory in order to figure out where the unbalanced retain is that's causing the leak. The Strings allocated by PMJSON end up in the JSON enum, which you're probably then decoding into your own model structs. If your own model struct then gets leaked, the string data being leaked will have been allocated by PMJSON, but leaked in your app.

@iDevPro
Copy link
Author

iDevPro commented Jan 18, 2019

I found issue. And this issue not in PMJSON :)))))

2019-01-18 12 42 33

This issue in Swift string, any append, concatenate of string cause memory leak...
I have another place of my code when no any objects, only value type and get this leak too

@iDevPro iDevPro closed this as completed Jan 18, 2019
@lilyball
Copy link
Collaborator

That sounds extremely unlikely. Again, what you're showing is just where the memory was allocated, not where it was leaked.

@iDevPro
Copy link
Author

iDevPro commented Jan 21, 2019

That sounds extremely unlikely. Again, what you're showing is just where the memory was allocated, not where it was leaked.

But this screenshot from Leak items :) I found so many memory leaks in String on iPad Air 2 simulator with iOS 9.3, on iPad Air Simulator with iOS 10 and up there is no memory leaks ;)

@lilyball
Copy link
Collaborator

@iDevPro That screenshot is showing where the memory was allocated. That's not the same thing as where it was leaked. In order to figure out what's responsible for the leaking you have to drill into the object's history in the Allocations instrument and pair up the retain/release calls. If you find an unbalanced retain, the missing release is responsible. If you don't find any unbalanced retain/release pairs then the missing release must be the final release, but in this particular case I believe you've identified the _StringGuts object as the thing being leaked, and in that particular code path you screenshotted, when it allocates a new _StringGuts, it does release the old _StringGuts.

All this to say, the String is allocated at the spot where you've screenshotted, but then it's handed to your application, which can then do whatever it wants with it. If your application leaks the string, the fact that it came from PMJSON is irrelevant.

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

No branches or pull requests

2 participants