【发布时间】:2010-02-17 06:44:31
【问题描述】:
仅使用 UIView 的子类时出现内存泄漏。它泄漏了 128 个字节并一直向下通过 CoreGraphics 等。我的子类只是一个生成的骨架,其中没有任何内容。当我只使用 UIView 而不是 ScrollView 时,不会报告泄漏。它可能是什么,我错过了什么?
非常感谢, 亚历克斯。
======================================
//---- main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
// NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"testScrollViewAppDelegate");
// [pool release];
return retVal;
}
//---testScrollViewAppDelegate.h
#import <UIKit/UIKit.h>
@interface testScrollViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}
@property (nonatomic, retain) UIWindow *window;
@end
//--testScrollViewAppDelegate.m
#import "testScrollViewAppDelegate.h"
#import "ScrollView.h"
@implementation testScrollViewAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor whiteColor];
CGRect frame = CGRectMake(10, 150, 300, 200);
ScrollView* scrollView = [[ScrollView alloc] initWithFrame:frame];
[window addSubview:scrollView];
[scrollView release],scrollView = nil;
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
//-- ScrollView.h
#import <UIKit/UIKit.h>
@interface ScrollView : UIView {
}
@end
//-- ScrollView.m
#import "ScrollView.h"
@implementation ScrollView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
}
- (void)dealloc {
[super dealloc];
}
@end
【问题讨论】:
标签: iphone memory uiview subclass memory-leaks