我宣佈以下變量作爲實例變量,並在我的m文件中使用它,但是我收到警告。Obj-C,在線分配的對象的潛在泄漏,警告?
TransparentToolbar *tools;
就行分配的對象的潛在泄漏...
我曾嘗試創建一個屬性,例如..
@property (nonatomic, retain) TransparentToolbar *tools;
而且synthesize'ing並將其釋放,但是我的觀點在dealloc結束時崩潰了。
我在做什麼錯?
編輯在pickerSortingDataCurrent同樣的警告......
h
@interface myViewController : UIViewController <UIActionSheetDelegate,
UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDelegate,
UITableViewDataSource, MFMailComposeViewControllerDelegate> {
TransparentToolbar *tools;
NSArray *pickerSortingDataCurrent;
}
@property (nonatomic, retain) TransparentToolbar *tools;
@property (nonatomic, retain) NSArray *pickerSortingDataCurrent;
m
@synthesize pickerSortingDataCurrent;
@synthesize tools;
- (void)viewDidLoad {
[super viewDidLoad];
tools = [[[TransparentToolbar alloc]
initWithFrame:CGRectMake(0, 0, 70, 44.01)] autorelease];
tools.barStyle = UIBarStyleBlackOpaque;
self.pickerSortingDataCurrent = [[NSArray alloc] initWithObjects:
@"Next Date Ascending",
@"Next Date Descending", nil]; // removed some items here
}
- (void)dealloc {
[tools release];
[pickerSortingDataCurrent release];
[super dealloc];
}
AHHHH我已經自動釋放....但這並不解決pickerSortingDataCurrent ...
編輯...
#import "TransparentToolbar.h"
@implementation TransparentToolbar
- (void)drawRect:(CGRect)rect {
// do nothing in here
}
- (void) applyTranslucentBackground
{
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
self.translucent = YES;
}
- (id) init
{
self = [super init];
[self applyTranslucentBackground];
return self;
}
// Override initWithFrame.
- (id) initWithFrame:(CGRect) frame
{
self = [super initWithFrame:frame];
[self applyTranslucentBackground];
return self;
}
@end
其他編輯
很難不代碼說。 – Max
你可以包含你的'dealloc'代碼嗎? – Jef
我遇到了同樣的問題,我在viewDidLoad中填充了一個接口數據數組,請參閱上面的編輯。 – Jules