Skip to content

Commit

Permalink
Merge pull request #6 from jimmaye/nsurlsessionleak
Browse files Browse the repository at this point in the history
address memory leak issue with regards to NSURLSession
  • Loading branch information
danialzahid94 authored Jun 2, 2017
2 parents 476b972 + 8398c0e commit 55a182a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions EventSource/EventSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @interface EventSource () <NSURLSessionDataDelegate> {

@property (nonatomic, strong) NSURL *eventURL;
@property (nonatomic, strong) NSURLSessionDataTask *eventSourceTask;
@property (nonatomic, strong) NSURLSession *session;
@property (nonatomic, strong) NSMutableDictionary *listeners;
@property (nonatomic, assign) NSTimeInterval timeoutInterval;
@property (nonatomic, assign) NSTimeInterval retryInterval;
Expand Down Expand Up @@ -115,6 +116,7 @@ - (void)close
{
wasClosed = YES;
[self.eventSourceTask cancel];
[self.session finishTasksAndInvalidate];
}

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
Expand Down Expand Up @@ -220,11 +222,14 @@ - (void)_open
[request setValue:self.lastEventID forHTTPHeaderField:@"Last-Event-ID"];
}

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
delegate:self
delegateQueue:[NSOperationQueue currentQueue]];
if (self.session) {
[self.session invalidateAndCancel];
}
self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]
delegate:self
delegateQueue:[NSOperationQueue currentQueue]];

self.eventSourceTask = [session dataTaskWithRequest:request];
self.eventSourceTask = [self.session dataTaskWithRequest:request];
[self.eventSourceTask resume];

Event *e = [Event new];
Expand Down

0 comments on commit 55a182a

Please sign in to comment.