内存泄漏。我怎样才能修复它们

时间:2013-07-24 12:52:24

标签: ios memory-leaks

我收到了几次内存泄漏。所有代码中都有最后一个位置 - [ASIHTTPRequest somemethod]。之前我以为是ASIhtt Library泄漏了内存。但是看起来它可能只是指向创建对象的位置,并且代码中实际上存在泄漏原因。下面是一个内存泄漏堆栈的示例。我需要知道如何解决这些问题。我的方法应该是什么。感谢

   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

3 个答案:

答案 0 :(得分:6)

  1. 启用ARC
  2. 停止使用ASIHTTPRequest。开发人员发布在网站顶部:

      

    请注意,我不再使用此库 - 您可能需要考虑为新项目使用其他内容。

    认真!图书馆的最后一次更新是两年多以前的事了!

  3. 开始使用AFNetworking

答案 1 :(得分:0)

我建议使用仪器中的Leaks工具。 Here is a tutorial帮助您入门。

答案 2 :(得分:0)

通过Xcode分析 - >产品 - >分析 它将通过Blue指示器显示所有内存泄漏的位置。 看到这一点,并试图消除那些潜在的潜在泄漏。