Question: I'm currently developing an iOS application which was started by another developer. 

Usually, I make a property for every instance variable (assign for int, bool etc. / retain for all classes).

So in my projects, this line causes a leak:

```
myVar = [[NSString alloc] init]; (alloc/init +1, retain in setter +1, release in dealloc -1 => +1)

```

So I use:

```
NSString *tmpMyVar = [[NSString alloc] init];
[self setMyVar: tmpMyVar];
[tmpMyVar release];

```

Or:

```
NSString *tmpMyVar = [[[NSString alloc] init] autorelease];
[self setMyVar: tmpMyVar];

```

In this new project, the previous developer didn't use @property/@synthesize so I'm wondering what will be the result of the previous line of code in this context (it doesn't call setter I guess)? Memory Leak?

The previous developer releases variable in dealloc method, just like me.

Thank you very much!

Answer: 
Since it directly assigns the instance variable to the allocated object it's retain count is 1 (because, like you said, a setter isn't called).
And because it's released in dealloc, it's all balanced out. So no memory leaks.

> 
> So in my projects, this line causes a leak:
> 
> 
> myVar = [[NSString alloc] init]; (alloc/init +1, retain in setter +1, release in dealloc -1 => +1)
> 
> 
> 

No,it wouldn't even in your projects, because, as you pointed out, no setter is used.

Also, when using properties, it is the recommended way to access instance variables directly in the init method, instead of using setters.

To inspect for questionable memory-leaks like your example, also use the clang static analyzer or instrument's leak tool.
You need to look at the other developer's setter implementation. Make sure they release the existing value and retain the new value; something like:

```
- (void)setMyString:(NSString *)string
{
    [string retain];
    [_string release];    // ivar
    _string = string;
}

```

The only advantage to implementing your own setter/getter methods is to do something (other than setting the ivar) when a value is set. If the methods don't do anything like this then why not change all implementations to `@property/@synthensize`?