Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is modern runtime?

Note: Typically in a dealloc method you should release object instance variables directly (rather than invoking a set accessor and passing nilas the parameter), as illustrated in this example:

- (void)dealloc {
    [property release];
    [super dealloc];
}

If you are using the modern runtime and synthesizing the instance variable, however, you cannot access the instance variable directly, so you must invoke the accessor method:

- (void)dealloc {
    [self setProperty:nil];
    [super dealloc];
}

What is modern runtime in iOS application development exactly?

like image 411
Pablo Avatar asked Jul 06 '11 06:07

Pablo


People also ask

What do you mean by runtime?

Runtime is a stage of the programming lifecycle. It is the time that a program is running alongside all the external instructions needed for proper execution. Some of these external instructions are called runtime systems or runtime environments and come as integral parts of the programming language.

What is an example of a runtime environment?

One of the best examples of a runtime environment is Java: The Java Runtime Environment is a prerequisite for running Java programs. This makes Java programs largely independent of operating systems and thus able to be executed in any operating system with the right runtime environment.

What are the different types of runtime environments?

The OMEGAMON® products support three types of runtime environments: base, full, and sharing. A sharing environment may share libraries with a base runtime environment, a full runtime environment, or an SMP/E runtime environment.

Why is it called runtime?

The name comes from the compile time and runtime division from compiled languages, which similarly distinguishes the computer processes involved in the creation of a program (compilation) and its execution in the target machine (the run time).


1 Answers

It is possible to access the ivar directly, under the same name as the synthesized property. The @synthesize directive creates the ivar on your behalf if one does not already exist, and since that is a compiler directive, the ivar is available at compile-time. See "Runtime Difference" in the Declared Properties chapter of The Objective-C Programming Language. As Abizern noted in a comment, it's also possible to specify whatever name you like for the ivar: @synthesize coffee=tea; -- here, tea is the ivar and coffee the property.

To use the ivar, simply refer to it like any other variable, without using the dot syntax. The following is all perfectly legal and works as expected:

@interface Grisby : NSObject {}
@property (retain) NSObject * obj;
@end

@implementation Grisby

@synthesize obj;

- (void) dealloc {
    [obj release], obj = nil;
    [super dealloc];
}

- (id) init {
    self = [super init];
    if( !self ) return nil;

    obj = [NSObject new];

    return self;
}

- (NSObject *) obj {
    return [[obj retain] autorelease];
}

@end

The "modern runtime" was introduced with Mac OS X 10.5 (Leopard) as part of the transition to 64-bit. All versions of iOS use the modern runtime. Synthesized instance variables are a feature of the modern runtime, as noted in the link I provided above.

The other key difference, noted in "Runtime Versions and Platforms" of the Objective-C Runtime Programming Guide, is that instance variables are "non-fragile". There is a layer of indirection added to ivar storage and access which allows classes to add variables without affecting the storage of derived classes. It also presumably facilitates instance variable synthesis. Greg Parker has an explanation involving kittens, there's passing reference to it in Mike Ash's 2009 runtime writeup, and Bavarious here on SO has a swell post about ivar storage and class extensions.

You can see other things that changed, though without explanation, in the "Mac OS X Version 10.5 Delta" chapter of the Objective-C Runtime Reference.

like image 88
jscs Avatar answered Sep 27 '22 20:09

jscs