Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

iphone - Objective C: retain vs alloc -


i have singleton class code:

manager.h

@interface manager : nsobject {   nsstring *jobslimit;   nsmutabledictionary *jobtitles; }  @property (nonatomic, retain) nsstring *jobslimit; @property (nonatomic, assign) nsmutabledictionary *jobtitles;   @implementation manager  @synthesize jobslimit; @synthesize jobtitles;  + (id)sharedmanager {     @synchronized(self) {         if(shared == nil)             shared = [[super allocwithzone:null] init];     }     return shared; }  - (id)init {     if (self = [super init]) {           jobslimit = [[nsstring alloc] initwithstring:@"50"];         jobtitles = [[nsmutabledictionary alloc] init];     }     return self; } 

then in code i'm assigning these variables this:

 self.jobslimit = [nsstring stringwithformat:@"%d", progressasint];  [self.jobtitles addentriesfromdictionary:anotherdictionary];   - (void)dealloc {     [super dealloc];     [jobslimit release];     [jobtitles release]; } 
  • now question code correct? assignment correct?

  • i'm confused when use alloc and/or retain. need use alloc if property retained? , if use alloc should property assign?

  • what reference count these variables , dealloc'd/under-dealloc'd when dealloc called?

  • also singleton classes need initialize ivars in init method above or not have to.

i'd appreciate if can me clear confusion out , in advance.

regards,

your code looks correct, perhaps explanation in order, since sounds you're little unsure.

when assign property has retain semantics using "." syntax, accessor method calls retain. "." syntax shorthand invoking accessor method, so

self.jobslimit = [nsstring stringwithformat:@"%d", progressasint]; 

is same as

[self setjobslimit:[nsstring stringwithformat:@"%d", progressasint]]; 

that works out to:

  • create (autoreleased) string numeric value
  • retain string (you own it) , assign jobslimit

if, on other hand, assign ivar directly (not using "."-accessor), setter method not called. example:

jobslimit = [[nsstring alloc] initwithstring:@"50"]; 

that is:

  • allocate string (you own it), value "50"
  • assign jobslimit

either way, own string referred jobslimit, , responsible releasing (e.g., in dealloc method).


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -