possible memory leak ios 9.0.2
Sending messages with a GCDAsyncUdpSocket in an iOS app (SpriteKit), makes the Memory indicator in the debugging sidebar in XCode go up and never comes down ( I reached 500+ MB at one time after a lot of usage, and the app only starts with 10 MB). I did not manage to find where the leak comes from with Instruments , but by trial and error, I managed to figure out it only happen when I send a message
My code [_clientSocket sendData:data toHost:host port:port withTimeout:-1 tag:1];
Which goes to GDCAsyncUdpSocket.m:
- (void)sendData:(NSData *)data toHost:(NSString *)host port:(uint16_t)port withTimeout:(NSTimeInterval)timeout tag:(long)tag
Tested with an iphone 6 / ios 9.0.2. A thing to note, the leak does not seem to be happening on an iPhone4 / iOS 7.
Any solution found ??
Actually , it would be good if someone could reproduce this (or not). I connected the xcode debugger to the application launched directly on the iphone, and there the memory is stable. Is it possible that it's actually a bug coming from XCode ? That might explain why it's not appearing on the iphone 4 ?
Hi , I am able to reproduce each and every every time , I am trying to send around 300MB video from one iPhone 5S (Sender )to IPhone 6S (Receiver), at Receiver side after reading each packet , memory getting acclimated and application memory increasing , which turning to crash due to memory shortage . I am guessing packet are not dequeuing after reading at receiver side .
How to ensure that packets are dequeued at receiver side after read.
Please let me know if you need any additional info .
Hi , I am able to reproduce each and every time . seems like read packets are not dequeued after reading could you please help me to fix this issue . it is bit very urgent . On 01-Jan-2016 3:42 pm, "eemerge" [email protected] wrote:
Actually , it would be good if someone could reproduce this (or not). I connected the xcode debugger to the application launched directly on the iphone, and there the memory is stable. Is it possible that it's actually a bug coming from XCode ? That might explain why it's not appearing on the iphone 4 ?
— Reply to this email directly or view it on GitHub https://github.com/robbiehanson/CocoaAsyncSocket/issues/390#issuecomment-168336356 .
You'll have much better results getting help on alleged memory bugs in FOSS projects if you can deliver a minimal, reproducible test case. That means a small project, easily read by someone else, that always reproduces the bug.
Since you have such a project, please post it somewhere, and perhaps someone will take a look.
Hi Everyone , Thanks for your reply . I am able to found cause for it . Actually it is fix with Xcode memory usage feature , Application runs properly if i am not debugging through Xcode . i have tried with Xcode 6.4 , 7 and 7.2 version all Xcode version have same issue
Simple test project to reproduce this problem: https://github.com/robbiehanson/CocoaAsyncSocket/files/101793/F53OSCLeakTest.zip
I get it regardless of what target I select in XCode. On a real device clicking the test button will leak 1MB.
It's appearing on my iPad with iPhone. Both ios9. Anyone Solved it?
I managed to get a constant memory usage in Xcode debugger , by doing some ugly modifications to the GCDAsyncUdpSocket.m file:
- first , I added a 2nd function by duplicating asyncResolveHost. I named it syncResolveHost and removed all the "dispatch_async" stuff from it, and including all the code of the functionin an @autorelease {} block. I imagine this removes all the 'async' magic from the function, but in my case it also removed the leaking.
- secondly, in this function:
- (void)sendData:(NSData *)data
toHost:(NSString *)host
port:(uint16_t)port
withTimeout:(NSTimeInterval)timeout
tag:(long)tag
I replaced the call to asyncResolveHost with a call to the newly duplicated syncResolveHost
//[self asyncResolveHost:host port:port withCompletionBlock:^(NSArray *addresses, NSError *error) {
[self syncResolveHost:host port:port withCompletionBlock:^(NSArray *addresses, NSError *error) {
and towards the end of the function i removed dispatch_async part:
//dispatch_async(socketQueue, ^{ @autoreleasepool {
[sendQueue addObject:packet];
[self maybeDequeueSend];
//}});
I know its far from 'fixing' it properly, but this seems to stop the leaking (or at least Xcode debugger does not show any more memory leaking).
It would be great if someone with more knowledge and comprehension of the code of this library would do the proper fixes.
I also found this on Apple developer forums:
https://forums.developer.apple.com/thread/19582
Seems people are saying it's a bug with xcode7 / ios9 concerning dispatch_async ...
@eemerge I read this page.
The problem seems to be on device only and only when running from XCode in the debugger - not if the app is started without the debugger.
I test my testProject not running from XCode in the debugger,and i observed its memory changes. Exciting! It did not happen memory leak. So it just Xcode debugger bug in ios9,don't be worried.
I filed a bug with Apple, will keep you updated.
请问有人解决了么?
What ?
[https://translate.google.com/] He's asking if someone has found a fix yet. I second that!
I write Chinese, I'm sorry! I want to ask the memory overflow problem solved? My IOS9.3 cannot be used normally, thank you for your reply
According to eemerge and puga1024 (see previous posts) the memory leak does not occurs when not debugging.
Quote "The problem seems to be on device only and only when running from XCode in the debugger - not if the app is started without the debugger."
Testing procedures directly collapse
Xcode 7.3 seems to have fixed the issue. So , I'd say it was related to Xcode and not to CocoaAsyncSocket. I will wait for some confirmations from people here who had the issue with XCode < 7.3 before closing the issue.
We are also facing the same problem with xcode 7.3.1 and ios9.2.1