views:

155

answers:

1

Hi All,

I have a memory leak when just using subclass of UIView. It leaks 128 bytes and goes all the way to down thru CoreGraphics etc. My subclass is just a generated skeleton without anything in it. When I use just UIView instead of ScrollView no leak are reported. What could it be and what I am missing?

Thanks a lot, ALex.

=====================================

//----  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
A: 

Why did you comment out the NSAutoreleasePool code? If there's no autorelease pool, a lot of ObjC and CF objects will be leaked.

(Also, please show us how did you implement -drawRect:.)

KennyTM
Commented by accident when posting it as I've played with different things trying to figure it out. There is nothing in a drawRect. I've just made an empty subclass of UIView in XCode. I had a problem in bigger app and here just try to minimize test example.
AAA