0

ARC is enabled in my project,I found in a post of this site that Cocoa creates an autorelease pool for you on the main thread, but doesn't do anything for you on background threads. If you're going to kick something off onto a background thread without using NSOperation or something, you'll want to wrap that thread in an @autoreleasepool ARC memory leaks I modified my code,still having memory leak issue.Please help. enter image description here

According to you Bryan Chen I have editedenter image description here

Now getting issue here enter image description here

enter image description here

enter image description here

Next modification enter image description here

Community
  • 1
  • 1
user2799156
  • 367
  • 2
  • 3
  • 10
  • What profile in Instruments are you using to get these results? – zadr Nov 19 '13 at 06:03
  • Instruments doesn't have a "Provisioning" profile. When you Build for Profiling, and another app opens up, what do you select from the sheet that appears? – zadr Nov 19 '13 at 06:56
  • If you look at the list of objects, what does it say is leaking? That's more likely to help than random screenshots of code. – zadr Nov 19 '13 at 07:06

2 Answers2

0

put @autoreleasepool in your first dispatch_async (jsonParsingQueue)

Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
0

Note that when you dispatch_async a block to the main queue, that block will be executed on the main thread and therefore already has an autorelease pool. Therefore the autorelease pool in your existing code is unnecessary where it is, and should be moved such that it encloses the entire contents of the block being dispatched to the jsonParsingQueue.

EDIT: Actually, all GCD queues do have autorelease pools automatically, so although it can be useful to create an additional pool to have better control over memory use, it should not cause a leak if you don't. I think you might have another issue.

See here for reference: Do you need to create an NSAutoreleasePool within a block in GCD?

Community
  • 1
  • 1
NSAdam
  • 181
  • 4
  • Edited according to you still having issues – user2799156 Nov 19 '13 at 05:22
  • Your @autoreleasepool is still not quite in the right spot. It should enclose the contents of the block being dispatched to the jsonParsingQueue. That is, it should start after the line that looks like `dispatch_async(jsonParsingQueue, ^{` and end on the line after the `});` that closes the inner dispatch_async. – NSAdam Nov 19 '13 at 05:54