retain

retain cycle with core-data

Hello, I think I have a problem, maybe linked to a retain cycle in Core-Data. The code is a follow, where self.image is also a NSManagedObject: - (void)setImage:(UIImage*)image1 andThumbnail:(UIImage*)image2 { self.image.data = UIImageJPEGRepresentation(image1, 0.85); // This is autoreleased self.thumbnail = UIImageJPEGRepresen...

Is there an automatic release with setTitle (UIButton class) ?

Hello, As everyone knows, setTitle automatically retains the string passed as a parameter. When the button caption needs to be changed, I guess that it is necesary to release the current (old) string before setting the new one. I wonder what is the most elegant way to dot it. See my code sample (here, getPlayerHandFromGame method produ...

many retains placed on NSURL when using arrayWithContentsOfURL

I am creating an NSArray from a URL that points to a plist NSLog(@"_url rc:[%d]",[_url retainCount]); //prints "_url rc:[1]" content = [NSArray arrayWithContentsOfURL:_url]; NSLog(@"_url rc:[%d]",[_url retainCount]); //prints "_url rc:[10]" I'm completely at a loss as to why this is occurring. Let me know if you need further informat...

How can I do retain operation during deleting an observation in SAS?

The problem, that if the else is executing, increment of S will not accomplish. Any idea? data osszes_folyositas; set osszes_tabla; retain old_xname; retain s 0; if xname ne old_xname then do; old_xname = xname; s = 0; end; else do; s = s + Foly_s_tott_t_rgyh_ban_HUF; delete; end; run; ...

Handling an external screen on the iPad

Ok, I think its possible I've misunderstood the correct way to implement an external screen on the iPad and it is causing me a lot of headaches. Since this is a long post, what I'm trying to do is create and send a view to an external screen over VGA, and remove the screen once I'm done with it. I'm having retain count issues so can't ge...

alloc + init with synthesized property - does it cause retain count to increase by two?

I've seeen the following snippet quite a bit: In the header: SomeClass *bla; @property(nonatomic,retain) SomeClass *bla; In the implementation file: @synthesize bla; and then self.bla = [[SomeClass alloc] init]; I think that this assignment puts the retain count for 'bla' up by two; once through the alloc/init call, then throug...

Possible scenarios of using alloc/retain/release on iPhone?

Hi, I have been using ojective c for almost a week, and I am mainly a c++ coder. After I read Apple's memory management guide, I try to bring my memory usage style in c++ into objective c... I tried to conclude these scenarios, I think I won't make memory mistake if I follow these instructions. Please kindly let me know if I am wrong :...

NSMenuItem -setTarget: Does it retain the target?

NSMenuItem -setTarget: Does it retain the target, or should one explicitly retain it? I've seen conflicting docs on this. I know of retainArguments in NSInvocation, but I'm not sure this applies to NSMenuItem as it doesn't inherit from NSInvocation. ...

Iphone - begginer questions - retain data member and Notifications

Hi, Just need 2 really basic clarifications. 1. Lets say I have a class A which has a member delcared like: @property (nonatomic,retain) NSString* stringInstanceVariable ; In one of my methods, I want to initialize stringInstanceVariable to be some string. Do I need to retain it or not ? should I call: stringInstanceVariable = [[NS...

Retain and self with NSMutableArray

In my .h file I have a NSMutableArray *locationsArray defined with a property as follows @property (nonatomic, retain) NSMutableArray *locationsArray In my .m file I was displaying a table view, this loaded fine until I tried to roll-up at which point I it crashed with bad access. This was due to the locationsArray not being retained...

Reference on when to release in Objective-C

I'm having a recurring problem in Objective-C. I'm either releasing things too many time, or not enough. or perhaps I'm not retaining them enough... Can someone point me at a good reference that will give me a rule of thumb on when I need to retain and release? For example: I remember reading somewhere that some objects come pre-ret...

Memory release problems in Objective-C

I have a real-life example that I have in my project below. My aim is to pick out the most likely phone number for SMS receptions, and only that (phone)number. All works well when I don't release memory at the end, but we can't have that, can we. My question is: Where (and how) is the correct way to release memory in the example below? ...

Why do variables initialized in viewDidLoad not retain value in Objective-C?

I have a class I wrote called Location that just holds some strings. I'm using two instances of that class in a view controller, and when I initialize the two variables in viewDidLoad, they work fine for that method, but then when I try to use them later they are null. I have them set as retained properties. I have tested them and kno...

Unexpected retain count after calling CFMakeCollectable

I have this bit of code: CFDictionaryRef lDictionary = AACreateDictionaryForFile(path); if (lDictionary) { printf("retct before: %ld\n", CFGetRetainCount(lDictionary)); CFMakeCollectable(lDictionary); printf("retct after: %ld\n", CFGetRetainCount(lDictionary)); return TRUE; } else { return FALSE; } Su...

Retain Count for substringToIndex

I have an app that parses an XML doc & pulls out the info it needs. There are often a few matching items so the code iterates a few times. Instruments' Leaks tool keeps saying there is a leak on this line, self.currentDiscountedPrice = [parsedCharacters substringToIndex:(fullStopRange.location + 3)]; currentDiscountedPrice is a var de...

NSString Assignment & Retaining

Just a simple question on NSStrings, I have a piece of code that assigns a value to a string, depending on what is found it is either assigned a value by substringToIndex or the constant string @"0.00", is it okay to use // Save if value found, otherwise set to 0.00 if (parsedCharacters == nil || [parsedCharacters isEqualToString:@""]) ...

Retain count for tableView:cellForRowAtIndexPath:

In Apple's example code, the method tableView:cellForRowAtIndexPath: of a UITableViewDataSource returns a cell with a retain count of 1; it allocs it, but doesn't autorelease it. However, the static analyzer complains that this violates the Cocoa naming conventions, since the method name doesn't start with 'new', etc. The documentation d...

Objective C: @property(retain) doesn't call retain?

I was trying to track a strage memory allocation bug so I overrode the retain and release methods of my class. I noticed that when assigning an instance of this class to a property of another, the retain count of the object increased, but my redefined retain was never called. How can this be possible? Are (retain) properties retaining t...

retain C array in objective-c

i create a c array in the firstClass (this is created in the interface): BOOL taken[25]; i then go to a different view and come back to the first one, except my c array is reset to 0, how do i retain my array when i go back an forth between views? ...

How can I make sure nothing gets autoreleased?

I need a way to create variables that are accessible for the entire time my custom class is initiated to when I call the release function. I need to retain a NSDate and a NSString. ...