Use @property (to prevent the memory-leak error)

12 Mar 2012

See this example:

// In the init function UIView *v = [[UIView alloc] init]; [self addSubview:v]; _someVar = v [v release]; // In the dealloc function [_someVar release]; _someVar = nil;

Here is what caused the `EXC_BAD_ACCESS`, and it took me like 2 hours to solve it.

Notice that `_someVar` is released twice. It's super confusing.

Next time, just use `@property`.

And, when I want to release it, just set the property to nil.

You cannot really go wrong with `@property`…

Give it a kudos