retain

Behavior of retained property while holder is retained

Hello everyone, I am a beginner ObjectiveC programmer, coming from the C++ world. I find it very difficult to understand the memory management offered by NSObject :/ Say I have the following class: @interface User : NSObject { NSString* name; } @property (nonatomic,retain) NSString* name; - (id) initWithName: (NSString*) theName...

objective C NSString retain

If I create a String with [NSString StringWithFormat], do I have to [retain] it? My understanding is that convenience methods add the objects to autorelease pool. If that is the case, shouldn't we retain the object so that it doesn't get drained with pool at the end of the event loop? ...

Retain information in cocoa?

Hello, I'm still new to Cocoa and don't know much about memory management. I read up on Apple's documentation but I'm still confused. My question is if I set the value of a variable in a - (void)dowhatever when dowhatever ends, will the contents of the variable be erased? If so is there a method (without writing to a file) that I can us...

Retain, reuse, release?

I've got a series of buttons that each use a different image. Can I reuse a retained variable like this below: // set images UIImage *image = [[dice1 backgroundImageForState:UIControlStateHighlighted] retain]; [dice1 setBackgroundImage:image forState:(UIControlStateHighlighted|UIControlStateSelected)]; image = [dice2 backgroundImageForS...

Release Quickie

How to succinctly handle this situation. I'm not properly releasing contactDictionary in the if statement... NSNumber *pIDAsNumber; ... NSMutableDictionary *contactDictionary = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:kContactDictionary]]; if (!contactDictionary) { con...

Objective-C Basic class related question, retaining the value of a specific object using a class file

Members, scholars, code gurus. My background is far from any computer programming thus my question may seems basic and somewhat trivial to you. Nevertheless it seems that I can't put my head around it. I have googled and searched for the answer, just to get myself confused even more. With that, I would kindly ask for a simple explanation...

Objective-C Out of scope problem

Hi, I'm having a few problems with some Objective-C and would appreciate some pointers. So I have a class MapFileGroup which has the following simple interface (There are other member variables but they aren't important): @interface MapFileGroup : NSObject { NSMutableArray *mapArray; } @property (nonatomic, retain) NSMutableArray ...

Using NSThread to solve waiting for image from URL on the iPhone

So I have the following code in a method which I want to set a UIImageView image to that of one from an online source: [NSThread detachNewThreadSelector:@selector(loadImage) toTarget:self withObject:nil]; Then in the method called by the thread I have this: - (void) loadImage { NSURL *url = [NSURL URLWithString:logoPath]; // logo...

Objective-C / UIButton / SetTitle

Does the setTitle method of UIButton retain the NSString passed as argument ? I guess I can rely on the fact that the property is defined as: property(nonatomic,readonly,retain) UILabel *titleLabel In this case, I think that it does retain the string. Thanks, Apple92 ...

UIAlertView -show causing a memory leak

I'm relatively new to iPhone Development, so this may be my fault, but it goes against what I've seen. :) I think that I'm creating a UIAlertView that lives just in this vaccuum of the 'if' statement. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; if(!data) { // Add an ale...

Objective-C retain counts clarification

Hey, I kind of understand what's retain counts for. But not totally. I looked on google a lot to try to understand but still I don't. And now I'm in a bit of code (I'm doing iPhone development) that I think I should use them but don't know totally how. Could someone give me a quick and good example of how and why using them? Thanks! ...

Retain Count Question: Some Guidance, Please

[I'm sure this is not odd at all, but I need just a bit of help] I have two retain properties @property (nonatomic, retain) NSArray *listContent; @property (nonatomic, retain) NSArray *filteredListContent; and in the viewDidLoad method I set the second equal to the first (so now the retainCount is two, I think): self.filteredListCon...

array retain question

Hello, im fairly new to objective-c, most of it is clear however when it comes to memory managment I fall a little short. Currently what my application does is during a NSURLConnection when the method -(void)connectionDidFinishLoading:(NSURLConnection *)connection is called upon I enter a method to parse some data, put it into an array, ...

Retaining objects in game iphone

Hello - I am trying to create a game and have run into what is probably a pretty easy problem to solve. As the player goes through the game, many objects (Vehicle) will be added and removed. The Vehicles get added to an array called currentVehiclesMutableArray. My problem is I cant figure out how to retain a Vehicle so that it remai...

Retain count = 0 in other function? memory-management problem?

Hey guys, I declared a NSMutableArray in the header-file with: NSMutableArray *myMuArr; and @property (nonatomic, retain) NSMutableArray *myMuArr; In the .m file I've got a delegate from an other class: -(void)didGrabData:(NSArray*)theArray { self.myMuArr = [[[NSMutableArray alloc] initWithArray:myMuArr]retain]; } If I want to...

retain drop down value page posting back to itself asp.net

I have an aspx page that has... if (!IsPostBack) { PopulateBrand(); in the Page_Load. This PopulateBrand() simply populates my drop down. That works great and on post back it retains the value. The problem I'm having is that there is also a link on the page that is posting back some parameters to this page. What is h...

NSNumbers in stored array disappear.

So I stored an NSMutableArray of NSNumber objects into the file "times.plist" then I load it and retain it on launch and the NSLog shows the correct value, but later the [times count] equals 0. Why are the NSNumbers disappearing? times = [[NSMutableArray alloc] initWithObjects:[[NSNumber alloc] initWithFloat:time],nil]; ... [times writ...

iPhone .. NSString being released & dealloc -- but I cannot tell where or why...

This is KILLING me! I have a view. in the .h file i do this: @interface SearchLogs : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UIActionSheetDelegate, UIPickerViewDelegate> { NSString *startDate; NSDateFormatter *thisFormatter; } @property (nonatomic, retain) NSString *startDate; @property (n...

Why can't I retain a UIView-Pointer?

I'm trying to pass a UIView to another class - which kinda works, but I can't retain the pointer... in my .h file I declare the view: UIView *someView; I add the property @property (nonatomic, retain) UIView *someView; And in the .m-file I synthesize the property @synthesize someView; Then I have a method to set the view (which...

Obj-C: retainCount > 1 in dealloc method?

If a retain (reference) count of an object is greater than 1 in a dealloc method right before releasing does this mean there will be a memory leak? I was debugging my code to find another issue but then ran into this subtle one. One of my object's retain counts was 3 in the dealloc method. This object is a property with retain and is ...