Я занимаюсь разработкой игр для iPad.Я сталкиваюсь с этой вещью.Это мой пример кода:
Метод 1:
Foo.h
@interface Foo : UIView{
UILabel *title;
.... // Other objects like UISlider, UIbuttons, etc.
}
// I add @property for all the objects.
@property (nonatomic, retain) UILabel *title;
... blablabla
Foo.m
// I synthesize all the properties.
@synthesize title;
... blablabla
// Release in dealloc method
[title release];
....
[super dealloc];
Метод 2:
Foo.h
@interface Foo : UIView{
UILabel *title;
.... // Others object like UISlider, UIbuttons, etc.
}
// But this time I didn't add @property, synthesize and release.
Foo.m
// When I need the label, I allocate it:
title = [[UILabel alloc] initWithRect: CGRect(10, 10, 100, 30)];
title.text = @"test";
[self addSubview: title];
[title release];
Оба метода 1 и 2 работают, но в чем разница между 2методы (метод2 содержит меньше кода)?
Какой метод следует использовать и почему?
Это как-то связано с управлением памятью?