0

I am using instruments to resolve memory leak issues for an app in iPhone. I just wanted to know if I have to resolve the leaks coming from Foundation and CFNetwork Libraries. Specifically, the leaks are from:
1. NSCFString
2. NSConcreteData
3. General Block-3584
Since they do not directly point to the code that I have written, how should I resolve them, if I have to?

Thanks.

Lakshmie
  • 331
  • 6
  • 17

2 Answers2

1

It's almost certain that the memory leaks come from your code--there are almost no memory leaks in the Foundation libraries, providing you're testing on the device (there are memory leaks in the simulator, so you should always test on the device). It's not always immediately obvious where the leak comes from, and it's difficult to tell from your question, but I would guess it either comes from leaking an NSString (NSStrings are implemented with NSCFString under the hood) or a network-related class like NSURLConnection.

shosti
  • 7,332
  • 4
  • 37
  • 42
  • Ok, but if the error is from my code, wouldn't I get the error library to be my app's name? – Lakshmie Apr 22 '10 at 19:52
  • Oftentimes, the chain of method and function calling can be convoluted, especially if you're dealing with any threading or asynchronous methods. For example, if you're dealing with an `NSURLConnection`, the library may show up as `CFNetwork` (I'm not sure if that's the case off the top of my head, it's just a hypothetical example). That being said, there are a few leaks in the frameworks, and it's possible that you ran into one: see http://stackoverflow.com/questions/478242/leak-generalblock-3584. – shosti Apr 22 '10 at 20:25
  • I did a thorough check of my code. Everything that has been created using alloc has been released after its usage. Is there any other creation instance for which I need to release it? – Lakshmie Apr 22 '10 at 20:42
  • @Lakshmie: The only other times you need to `release` objects are for methods with `copy` or `new` in the method name (also, if you `retain` an object, you have to `release` it later). I may have spoken prematurely when I said it was "almost certainly" not framework code--the General Block-3584 leak looks like it may be from the framework. – shosti Apr 22 '10 at 21:18
  • Thanks. I had checked for all of them. I still do get NSConcreteData and NSCFString leaks and none of them is reported from my app. – Lakshmie Apr 22 '10 at 22:06
1

I experienced the same problems w.r.to memory leaks which were pointing to CFNetwork and Foundation framework. A small fix cleared all the memory leaks. While using aynchronous HTTP connection, I faced this problem.

Problem:

In the delegate, - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*) response,

I copied NSURLResponse and released.

Solution :

Dont copy and release NSURLResponse. Just use it as property asstype in your header file.

Kjuly
  • 34,476
  • 22
  • 104
  • 118
Sumanth
  • 11
  • 1