problem about retaincount-Collection of common programming errors


  • Ohad Regev
    objective-c memory-management automatic-ref-counting retaincount
    This question already has an answer here:How do I verify reference count in ARC mode?7 answersWhile using ARC, life is much easier in terms of memory management; but, let’s say I wish to look at a certain object while the app is running and see how many pointers are pointing to it at each certain point in the code. Is there a way to do that?

  • LuisABOL
    objective-c cocoa nsobject objective-c-runtime retaincount
    My question is how the current versions of Foundation (or of the Objective-C runtime library, since this seems to be there) implement retain count for NSObject derived objects? As I could see at NSObject.mm, there is no ivar called retain count in the NSObject’s interface body. Instead, there seems to be a kind of table or map which contains references counters for each object. But if retain count is really done with a map, aren’t retain and release operations too expensive with this kind of imp

  • lockedscope
    objective-c memory-management objective-c-blocks retain retaincount
    When ARC enabled, following code causes the obj retained twice for the block by calling objc_retain() and objc_retainBlock().(So retainCount becomes 3 after the block definition.)I checked that obj is not in autorelease pool and there are two objc_release() calls for obj at the end of the method. (I know counting retains does not make sense but i am checking the objc_retain() calls, not barely checking retain counts.) What is the rationale behind this?-(void)myMethod {NSObject *obj = [[NSObject

  • Andrey Chernukha
    objective-c memory-management copy retaincount
    I know that my question has already been discussed on StackOverflow but i found the answer not complete for my needs. So the question is:NSMutableArray *firstArray = [[NSMutableArray alloc] initWithObjects: obj1,obj2,nil]; NSMutableArray *secondArray = [[NSMutableArray alloc] init]; secondArray = [firstArray mutableCopy];what is retain count for the secondArray now? 2 or 1? Should i release it twice or just once? Does copy or mutableCopy increases retain count of the COPYING (secondArray in this

  • Josh Caswell
    objective-c cocoa reference-counting retaincount
    When I create an object and check its retain count, I get 1 as expected. When I release the object and then check the retain count again, it is still 1. Shouldn’t the object be deallocated, and the retain count 0?NSMutableString *str=[[NSMutableString alloc] initWithString:@”hello”]; NSLog(@”reference count is %i”,[str retainCount]); [str release]; NSLog(@”reference count is %i”,[str retainCount]);I do see 0 for the retain count if I set str to nil first. Why is that?

  • Thomas Clayson
    iphone release retaincount
    I’ve tested it and it looks like it does. So my question is, does it ALWAYS increment the retain count.So everytime I do something like this:UIView *theView = [[[UIView alloc] initWithFrame:(CGRect)aFrame] autorelease]; [self.view addSubview:theView];Am I actually leaking memory?I have a global property @property (nonatomic, retain) UILabel *ingredientsTextLabel; which I instantiate in viewDidLoad with this code:I just have the property named, theres no property for it in my header, so no getter

  • Nick Hutchinson
    objective-c instruments grand-central-dispatch retaincount nszombie
    I’m confused by an occasional crash that I’m seeing, which, according to the Zombies instrument, is caused by the over-release of some dictionary values. When I look at the object history for one of these overreleased objects in Instruments, I see that its retain count drops straight from +2 to 0 at one stage. (Take a look at the screenshots at the end of the post). It’s not clear to me how this is even possible. I should say that I only see this crash when profiling with Instruments, so I suppo

  • Shanti K
    iphone modalviewcontroller dismiss retaincount deallocate
    In my app, I use method [self DismissModalView…] to dismiss a search view, everything was ok in iOS 3 and iOS 4, but now I upgraded to XCode 4.2 and SDK 5, this method runs ok againts iOS 5 but when I test it against iOS 3 + 4, the application crashes with message log:[CALayer retainCount]: message sent to deallocated instance 0xc640b80.I tried to investigate but still not find out root cause, please help me!

  • mttrb
    ios retaincount
    Now I have a ClassA : NSObject, and then in the viewcontroller viewDidLoad, look at the under code:- (void)viewDidLoad {ClassA *a = [[ClassA alloc] init];NSLog(@”a retainCount = %d”, [a retainCount]);ClassA *b = a;NSLog(@”a retainCount = %d b retainCount= %d “, [a retainCount],[b retainCount]);[a release];NSLog(@”a retainCount = %d b retainCount= %d”, [a retainCount],[b retainCount]);[super viewDidLoad]; }The console output looks like:2012-11-02 14:43:35.437 RetainCountTest[1043:207] a retainCou

  • nikans
    cocoa memory-management release nil retaincount
    Here I got some ugly code:NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”yyyy”]; NSDate *date = [NSDate date]; NSString *textWithYear = [NSString stringWithFormat:@”text and year %@”, [dateFormatter stringFromDate:date] ]; [dateFormatter release]; NSLog(@”%i”, [dateFormatter retainCount]); // returns 1 !As you see, retains counter returns 1, which I suppose means that the object is not released. If I change that string to[dateFormatter release], d

  • PengOne
    objective-c ios uiapplicationdelegate addsubview retaincount
    I was wondering something about the app delegate of my app. Why can’t I release like this :-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {RootViewController *controller = [[RootViewController alloc]initWithNibName:@”RootViewController”bundle:[NSBundle mainBundle]];[self.window addSubview:controller.view];[controller release]; // Here’s my question[self.window makeKeyAndVisible];return YES; }I was almost sure that -addSubview method inc

  • Rudiger
    iphone memory-management uiview release retaincount
    I have an issue with releasing a view too many times. Although simple in theory because im moving uiview to uiview, which is a subclass of uiview and being animated and so on its not something that I can easily fix. It only crashes 10% and only under certain conditions and only 30% of the time even under these conditions.So in other words its kinda complex. Sometimes in my dealloc method the retain count of this UIView is already 1 (which gets released when the view is released) and so shouldn’

  • MadMaxAPP
    iphone exc-bad-access retain retaincount
    Serious Problem here… i’m getting ECX_BAD_ACCESS if i try to NSLog an instance variable of my custom object. Following Function is called in my ViewController, payload holds String Data which is pulled from a url.- (void) initVcardWithData:(NSString *)payload {NSLog(@”1. initVcardWithData”);aVCard = [[vcardItem alloc] initWithPayload:payload];VCardViewController *aVCardViewController = [[VCardViewController alloc] initWithVCard:aVCard];[self presentModalViewController:aVCardViewController anim

  • NJones

  • MattDiPasquale
    objective-c automatic-ref-counting retaincount unsafe-unretained
    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 *tableHeaderView = [[UIView alloc] init];These temporary variables don’t need to be retained because the objects they point to are guaranteed to keep positive retain counts for as long as the temporary variables are in scope. So, should I declare them as __unsafe_

  • Ron
    iphone memory cocos2d retain retaincount
    I am making an iPhone game. I want to release all objects that have been allocated or retained. In the dealloc function I am releasing all such objects, but then I realized that sometimes I end up releasing objects when they have not been allocated yet. So I figured I need to check if its retainCount is greater than zero or not before I release it.My question is:Do I just check if the retainCount is greater than zero and then release it?if([bg retainCount]!=0) {[bg release]; }orShould I release

  • Martin
    iphone memory-management properties retaincount
    My question looks like a dozen ones about releasing properties, but I can’t find the exact answer i’m searching for.When a property is declared with retain :@property (nonatomic, retain) NSString * myString;then@synthesize myString;It generates getters and setters with retaining and releasing operations. Okay.Of course, property must be released in dealloc.-(void)dealloc {[myString release];myString = nil;[super dealloc]; }So that’s clean.But what if i never use myString ? Is it pre-initialised

  • user2332733
    objective-c memory-management retaincount
    Have a look at this code-snippet with a simple retain/release scenario:#import <Foundation/Foundation.h>@interface SomeClass : NSObject @end@implementation SomeClass @endint main(int argc, const char * argv[]) {SomeClass *aClass = [[SomeClass alloc] init];NSLog(@”retainCount: %lu”, [aClass retainCount]);[aClass retain];NSLog(@”retainCount: %lu”, [aClass retainCount]);[aClass release];NSLog(@”retainCount: %lu”, [aClass retainCount]);[aClass release];NSLog(@”retainCount: %lu”, [aClass retain

Web site is in building