0

I am getting several memory leaks. All have the last place in the code -[ASIHTTPRequest somemethod]. Earlier I thought it was ASIhtt Library that is leaking memory. However it looks like it might just be pointing to the place where the object was created and cause of leak is actually with in the code. Below is an example of one of the stacks of memory leaks. I need to know how should I go about fixing these. What should be my approach. Thanks

   0 CoreFoundation _CFStreamSetClient
   1 CoreFoundation CFReadStreamSetClient
   // Below are Within code
   2 ProductSurvey -[ASIHTTPRequest scheduleReadStream] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/ASIHTTP/ASIHTTPRequest.m:3716
   3 ProductSurvey -[ASIHTTPRequest startRequest] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/ASIHTTP/ASIHTTPRequest.m:1382
   4 ProductSurvey -[ASIHTTPRequest main] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/ASIHTTP/ASIHTTPRequest.m:955
   5 ProductSurvey -[ASIHTTPRequest startSynchronous] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/ASIHTTP/ASIHTTPRequest.m:802
   6 ProductSurvey -[BaseRequest __processRequest:] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/WebServices/../BaseRequest.m:73
   7 ProductSurvey -[BaseRequest request] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/WebServices/../BaseRequest.m:109
   8 ProductSurvey -[EntityRevisionCheckRequest request] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/WebServices/EntityRevision/EntityRevisionCheckRequest.m:21
   9 ProductSurvey +[NetworkUtility revisionForEntityId:] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Networking/Utilities/NetworkUtility.m:21
  10 ProductSurvey -[AbstractEntity(Extension) toJSONForUpdate] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/DataPersistance/Categories/AbstractEntity+Extension.m:65
  11 ProductSurvey -[Room(Extension) toJSONForUpdate] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/DataPersistance/Categories/Room+Extension.m:104
  12 ProductSurvey -[RoomService push] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/Services/RoomService.m:56
  13 ProductSurvey +[SyncService pushEntityData:] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/SyncService.m:84
  14 ProductSurvey +[SyncService pushInOrder:] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/SyncService.m:291
  15 ProductSurvey +[SyncService pushAllDirtyChangesToServer] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/SyncService.m:69
  16 ProductSurvey +[SyncService push:] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/SyncService.m:479
  17 ProductSurvey +[SyncService syncLocalRemoteData] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/SyncService.m:220
  18 ProductSurvey -[BGSyncService processSync] /Users/Ila/Documents/Developer/Stryker/ProductSurvey/Syncing/BGSyncService.m:77
  19 Foundation __NSThread__main__
  20 libsystem_c.dylib _pthread_start
  21 libsystem_c.dylib thread_start
ila
  • 920
  • 12
  • 35

3 Answers3

6
  1. Enable ARC
  2. Stop using ASIHTTPRequest. The developer posts at the top of the site:

    Please note that I am no longer working on this library - you may want to consider using something else for new projects.

    Seriously! The last update to the library was more than two years ago!

  3. Start using AFNetworking

Community
  • 1
  • 1
Wayne Hartman
  • 18,369
  • 7
  • 84
  • 116
  • I tried to use AFNetworking. But while using ASIHttp I was using startSyncronous method , now in AFNetwork it has blocks and execution is not linear anymore. Is there a work around for this ? I am already running services on a background thread so sync execution wont block the UI. – ila Jul 25 '13 at 09:21
  • @ila don't use synchronous networking. Ever. Nevertheless, blocks allow you to follow more 'linear' programming because blocks can capture scope of variables outside the block. – Wayne Hartman Jul 25 '13 at 13:05
0

I would recommend using the Leaks tool in Instruments. Here is a tutorial to help get started.

Jake Spencer
  • 1,117
  • 7
  • 13
  • this is the stack from instruments itself. I am using that and i am bale to get the code locations but I am not able to see what is the cause of the leak. Should I post the code for all the methods being shown in this stack ? – ila Jul 24 '13 at 12:58
  • It would be very tedious if you start posting code for individual methods. Better review the documentation. –  Jul 24 '13 at 13:01
0

Analyze by Xcode->Product->Analyze It will shows where all the memory leaks by Blue indicator. See that and try to remove those un potential leaks.

  • Static analyzer is not accurate and cannot tell about runtime leaks. You should recommend/use Instruments(Leaks, Allocations) to check and fix the runtime memory leaks. – Amar Jul 24 '13 at 13:31