"Instruments"누출 분석기를 사용하여 게시 전에 앱을 정리하기 시작했습니다.배열의 객체에 대한 메모리 누수
내가 꽂을 수없는 누출을 발견했습니다. 그래서 문제를 설명하기위한 간단한 프로젝트를 만들었습니다. 아래 코드를 참조하십시오. 보기에 "테스트"절차를 테스트하기 위해 단추를 놓았습니다. 항상 누수가 발생합니다.
#import <Foundation/Foundation.h>
@interface theObj : NSObject {
는 NSString * theWord "theObj"라는 개체의 헤더 코드
첫째; } @property (비 원자력, 보유) NSString * theWord;
@end
#import "theObj.h"
@implementation theObj
@synthesize theWord;
-(id) initWithObjects: (NSString *) aWord;
{
if (self = [super init]){
self.theWord = aWord;
}
return self;
}
-(void) dealloc{
[theWord release];
[super dealloc];
}
@end
이제 뷰 컨트롤러
#import <UIKit/UIKit.h>
#import "theObj.h"
@interface LeakAnObjectViewController : UIViewController {
NSMutableArray* arrObjects;
}
- (IBAction)test;
@end
#import "LeakAnObjectViewController.h"
@implementation LeakAnObjectViewController
- (IBAction)test {
if (arrObjects == nil)
arrObjects = [[NSMutableArray alloc] init];
NSString* aStr = @"first";
[arrObjects addObject:[[theObj alloc] initWithObjects:aStr]];
[arrObjects removeAllObjects];
}
Objective-C? 아마도 언어에 태그를 지정해야합니다 (그렇지만 내가 맞을지는 확실하지 않습니다). –
질문을 할 때 더 많은 태그를 사용해야하며, 이는 작업중인 다른 기술에 알려주고 답변을 얻을 수있는 기회를 향상시킵니다. – VoodooChild