Re: Debugging retainCount
Re: Debugging retainCount
- Subject: Re: Debugging retainCount
- From: publiclook <email@hidden>
- Date: Wed, 16 Jul 2003 12:54:47 -0400
On Wednesday, July 16, 2003, at 11:22 AM, The Amazing Llama wrote
The following code works without problems and is exactly the same as
the code posted by The Amazing Llama with the following addition:
1) I added a line of code to set the color of ticks so I can see them
2) I added the missing methods needed by Mr. Llama's code because he
didn't post them and his bug is undoubtedly in them.
#import <Cocoa/Cocoa.h>
@interface TestAutoreleaseView : NSView
{
NSCalendarDate *startDate;
NSCalendarDate *endDate;
}
@end
@implementation TestAutoreleaseView
- (id)initWithFrame:(NSRect)frameRect
{
[super initWithFrame:frameRect];
startDate = [[NSCalendarDate date] retain];
endDate = [[[NSCalendarDate date] dateByAddingYears:100 months:0
days:0 hours:0 minutes:0 seconds:0] retain];
return self;
}
- (void)dealloc
{
[startDate release];
startDate = nil;
[endDate release];
endDate = nil;
}
- (NSCalendarDate *)startDate
{
return startDate;
}
- (NSCalendarDate *)endDate
{
return endDate;
}
- (float)xForDate:currentTick
{
return (float)([currentTick yearOfCommonEra] - [startDate
yearOfCommonEra]);
}
- (void)drawRect:(NSRect)rect
{
NSCalendarDate* currentTick = [[self startDate] copy];
NSCalendarDate* nextTick;
while ([currentTick isLessThanOrEqualTo:[self endDate]])
{
[[NSColor blueColor] set]; // publiclook: added so I can see
the ticks
NSRectFill(NSMakeRect([self xForDate:currentTick]-1, 0, 2, 10));
nextTick = [currentTick
dateByAddingYears:10 months:0
days:0 hours:0 minutes:0 seconds:0];
[currentTick release];
currentTick = [nextTick retain];
}
[currentTick release];
}
@end
Add a custom view to a window via IB. Set the custom view's class to
TestAutoreleaseView. Set the resize springs so that the view will
change size and therefore redraw when the window changes size. Build
and run. Resize the window a lot. There is no leak. There is no crash
from over releasing.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.