Questions tagged [retaincount]

-retainCount is a commonly misused method related to memory management of objects in the Cocoa and Cocoa Touch frameworks. It should never be used.

Quoting the NSObject documentation:

This method is of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

To understand the fundamental rules of memory management that you must abide by, read “Memory Management Policy”. To diagnose memory management problems, use a suitable tool:

  • The Clang Static analyzer can typically find memory management problems even before you run your program.
  • The Object Alloc instrument in the Instruments application (see Instruments User Guide) can track object allocation and destruction.
180 questions
4
votes
2 answers

No Sound Suddenly After Using AVAudioPlayer a lot -- Please Aid ["AppleAudioQueue.39.189049" (25) flags=0x2 errno=24]

I am a newbie and I am probably doing many things wrong, therefore, I really need your expertise and help! I am creating an music app that uses the AVFoundation Framework. As I test it on my Macbook and iOS Devices, it actually works pretty well in…
002boy
  • 41
  • 4
4
votes
1 answer

Why retain count in negative value?

Possible Duplicate: NSString retain Count Is it possible that any object has its retain count in negative value ? I have this code NSString *str = [[NSString alloc] initWithString:@"Hello World"]; NSLog(@"String Retain Count: %i", [str…
Muhammad Rizwan
  • 3,470
  • 1
  • 27
  • 35
4
votes
1 answer

What might be a strategy to detect a retain cycle in an object hierarchy programmatically?

I'm writing an ARC-enabled framework which creates a hierarchy of objects, not unlike Cocoa's view hierarchy. Each controller object can have several subcontrollers. Controllers may have references to each other, which poses the potential risk of…
4
votes
3 answers

Which increases the retain count: alloc or init?

When we need create an object and take ownership of it we write NSObject *someObject = [[NSObject alloc] init]; After that someObject's retain count will be equal to 1. Which method increases the count, alloc or init, and where in Apple's docs is…
Rostyslav Druzhchenko
  • 3,673
  • 3
  • 33
  • 38
4
votes
2 answers

RetainCount OK to use in this instance?

RetainCount == BAD retainCount is taboo, unreliable, unpredictable, and in general shouldn't be used. I don't use it anywhere in my code, but I have seen it in one class that I use in an interesting way. I have a class that runs a thread that runs…
Sam
  • 26,946
  • 12
  • 75
  • 101
3
votes
3 answers

Should I use __unsafe_unretained for temp variables?

Let's say I want to create a temporary variable, e.g.: To point to another long-living variable: __unsafe_unretained UIView *tableHeaderView = self.tableView.tableHeaderView; To point to an object I just created. __unsafe_unretained UIView…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
3
votes
1 answer

Is assigning self.string = @"" on an @property that's (retain)'d proper?

A philosophical question, of sorts. Is it proper to assign a constant string to an @property that's (retained)? Or, should I do self.string = [NSString stringWithString:@""]; Is there a memory leak? What if it's overreleased? It's a constant…
AWF4vk
  • 5,810
  • 3
  • 37
  • 70
3
votes
3 answers

Retain/ Release count problem. Clarification needed

Possible Duplicate: check retain count As i was playing with retain, release counts, i ran into a situation, i am not able to explain. Please help me understand it better: There is a class O. It contains no variables and does nothing. There is a…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
3
votes
5 answers

window addSubview release problem

I was wondering something about the app delegate of my app. Why can't I release like this : -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RootViewController *controller =…
Pierre
  • 10,593
  • 5
  • 50
  • 80
3
votes
1 answer

Handling memory leaks in factory methods

I am developing an objective C framework which will ship as a static library at the end. But when I integrate that library to an actual application (by adding the static library) in the leaks tools I see some memory leaks present. Here is an example…
Dilshan
  • 3,231
  • 4
  • 39
  • 50
3
votes
3 answers

Properly release ViewController when adding subview without navigationController

Something I run into a lot is not being able to create and destroy a ViewController properly when adding the ViewController.view as a subview not on a navigation controller. for example: MyViewController *myViewController = [[MyViewController…
Kyle
  • 1,662
  • 2
  • 21
  • 38
2
votes
3 answers

automatic reference counting (ARC) and retainCount

I am in the process of converting my project to use ARC, and ran into a special problem. I have a class that manages a cache of files that are downloaded from the network. Each file is stored in the iPhone filesystem, and an associated object is…
fishinear
  • 6,101
  • 3
  • 36
  • 84
2
votes
4 answers

My retainCount is increasing?

am trying here to build rss reader , the problem that when user finish read artical and press back the dealloc don't called and i got retainCount 6 & some times 7 !! i have lots of customized panels when back button pressed the view is poped and…
Yahia
  • 691
  • 1
  • 7
  • 24
2
votes
1 answer

Another "Retain, then Release" question

being a Cocoa/Obj-C newbie I am going through the "Cocoa Programming for Mac OS X" book by Aaron Hillegass and - leaving apart the fact that now we have also the chance to use GC to avoid all this reasoning - I am not sure I get the reason for some…
Fabrizio Prosperi
  • 1,398
  • 4
  • 18
  • 32
2
votes
1 answer

UIView not being released correctly

I have a large hierarchy of view/viewcontrollers. In the main controller I have the following code where aViewController is a member of MyClass: @implementation MyClass ... - (void) viewDidLoad { [self.view addSubview:aViewController_.view]; …
Egil
  • 4,265
  • 4
  • 20
  • 13
1
2
3
11 12