-
Notifications
You must be signed in to change notification settings - Fork 601
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
In Test cases, Fix potential memory leaks by use of NSURLSession #250
Conversation
NSURLSession documentation states: “Important: The session object keeps a strong reference to the delegate until your app explicitly invalidates the session. If you do not invalidate the session, your app leaks memory.” http://tinyurl.com/jnb6642
I anticipated my CHANGELOG link to the PR incorrectly. I thought it would be 249, turns out it's 250. |
@mikelupo Just push a new commit on your branch to fix that link. No need to create a different PR or whatnot, it's just a new commit to add on your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that big a deal, but if you could remove any space from empty lines so that the diff could be reduced, that would be awesome!
You should be able to do that in Xcode by going into the Preferences > Text Editing > Editing tab > Check the 2 boxes in the "While editing: …" section. Then validate, and select all the text in this modified file an hit Ctrl-I to make Xcode re-indent your code and remove trailing spaces in whitespace-only lines.
CHANGELOG.md
Outdated
@@ -1,7 +1,9 @@ | |||
# OHHTTPStubs — CHANGELOG | |||
|
|||
## Master | |||
|
|||
* Fixed potential memory leaks with use of NSURLSession as detected by our devs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add two spaces after the .
(like you can see for other entries).
(This is a Markdown-specific stuff that makes the text on the next line actually be rendered in a new line in same paragraph instead of being joined on the same line)
@@ -366,6 +375,7 @@ - (void)test_NSURLSessionCustomHTTPBody | |||
|
|||
requestWithBody.HTTPBody = [@"somethingElse" dataUsingEncoding:NSUTF8StringEncoding]; | |||
[[session dataTaskWithRequest:requestWithBody] resume]; | |||
[session finishTasksAndInvalidate]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you fix the indentation here? (use spaces so that we're sure it matches the rest of the code which already uses spaces too). Yeah, I know, that old war again 😄
@@ -45,14 +45,15 @@ - (void)setUp | |||
{ | |||
[super setUp]; | |||
[OHHTTPStubs removeAllStubs]; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to get rid of those changes? 🙏 (by using the trick in the Xcode prefs I mentioned you in the last review or even manually of you don't want to change your prefs, that works too)
Basically all empty lines should really be empty and not contain indentation and spaces. I know it's nitpicking and a matter of taste, I don't care for one style or another but I care about consistency throughout the code base 😉
@@ -110,18 +111,18 @@ - (NSHTTPURLResponse *)runLogin | |||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url | |||
cachePolicy:NSURLRequestUseProtocolCachePolicy | |||
timeoutInterval:60.0]; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if course that applies to everywhere it changed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AliSoftware, Sorry I missed that. It's fixed now. My Xcode is already up as you mentioned, but I just didn't CTRL-i to repair the indentation on that one file. It's in the new commit of this PR now.
oh, I think I've been misunderstanding you. You want me to remove all the blank line fixes. Those blank lines had spaces where there should not have. And since I was in those files, I fixed those purposefully. Gerrit (our local code review tool) catches those and they show up as red space. We are diligent to remove "red space" as leaving it in in typically causes merge conflict headaches down the road. |
Oh wait… I totally got it the other way around, my bad, you're right! What I didn't realize when I wrote that comment here is that by the time I started writing My concern is I want things to be consistent all across the codebase. So I'd agree that we should remove all the spaces from empty lines and since I never realised that it wasn't the case already in that (quite old now) codebase of OHHTTPStubs I never thought of re-auditing it for it 😉 In light of that you have two choices, I'll let you decide which you like best:
I'll let you decide if you prefer to split that in 2 PRs (memleaks + remove spaces from empty lines) or all in that current one. I'd personally prefer two separate PRs, but would understand if it's too much work for you. In any case, just make sure that the spaces are consistent everywhere (and not in one way on some files and another in other files) |
🎉 Thx again @mikelupo for the fix and taking the time to follow our strict guidelines 😜 |
You're very welcome! Glad to be able to contribute to a really great app. The strict guidelines are what keeps it stable and easy to maintain. |
NSURLSession documentation states:
“Important: The session object keeps a strong reference
to the delegate until your app explicitly invalidates the
session. If you do not invalidate the session, your app
leaks memory.”
http://tinyurl.com/jnb6642
Checklist
Description
NSURLSessions can leak according to the Apple docs. So I've fixed the tests that use them.
Fixed a test that was failing (not due to my changes). "Task created in a session that has been invalidated"
I've removed some invalid whitespace (caught by our own Gerrit).
Motivation and Context
Memory leaks which can contribute to unexpected and hard to diagnose improper test behavior.
I ran the tests in XCode. Passing 100%.