Re: Thread memory leak (summary and thanks!)
Re: Thread memory leak (summary and thanks!)
- Subject: Re: Thread memory leak (summary and thanks!)
- From: Chuck Rice <email@hidden>
- Date: Sat, 7 Jun 2003 09:45:50 -0700
Thanks for your answers. I learned a lot.
1) NSDate gets storage that is only released with a [pool release];
2) Long lived threads need to have an inner pool that will release
every so often
3) The usleep(1000) command is cool and better suited to my needs
For those of you that asked, I am sending data to a graphic LCD
display via a KeySpan USB adaptor (USA19Qi) to a Matrix Orbital
Graphics LCD (GK24064-25).
<
http://www.keyspan.com/>
<
http://www.matrixorbital.com/>
This is for a car-trunk MP3 player and the display is the dashboard
display for the unit. The thread in question is below.
Thanks again for your help. -Chuck-
//--------------------------------------------------------------------------------------------------
// updateDisplay
//--------------------------------------------------------------------------------------------------
- (void)updateDisplay
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i;
char a;
int hbIndex = 0;
int heartbeat[20] = {163,164,165,166,162,162,162,166,165,164,163};
unsigned long ticktime;
[NSThread setThreadPriority:0.2];
while (TRUE) {
NSAutoreleasePool * pool2 = [[NSAutoreleasePool alloc] init];
if (initDisplay) {
[self drawOutlineRectangleWithColor:-1 x1:1 y1:01 x2:3 y2:10];
[self drawOutlineRectangleWithColor:-1 x1:1 y1:10 x2:3 y2:20];
[self drawOutlineRectangleWithColor:-1 x1:1 y1:20 x2:3 y2:30];
[self drawOutlineRectangleWithColor:-1 x1:1 y1:30 x2:3 y2:40];
[self drawOutlineRectangleWithColor:-1 x1:1 y1:40 x2:3 y2:50];
[self drawSolidRectangleWithColor:0 x1:3 y1:1 x2:3 y2:50];
[self drawLinex1:1 y1:56 x2:240 y2:56];
volumeNeedsUpdate = TRUE;
heartbeatNeedsUpdate = TRUE;
menuNeedsUpdate = TRUE;
initDisplay = FALSE;
}
if (volumeNeedsUpdate) {
volumeNeedsUpdate = FALSE;
[self writeToBarGraph:1 value:volume];
}
if (TickCount()>ticktime) {
ticktime = TickCount()+(6); // 60 ticks to the second, so 10
ticks is 1/10th second
heartbeatNeedsUpdate = TRUE;
}
if (heartbeatNeedsUpdate) {
heartbeatNeedsUpdate = FALSE;
if ((++hbIndex)>11) {hbIndex = 0;}
a = heartbeat[hbIndex];
[self setFont:6];
[self setPixelCursorX:1+(currentMenu*48) y:55];
[self sendLCDdataByte:&a];
}
if (menuNeedsUpdate) {
menuNeedsUpdate = FALSE;
hbIndex = 0;
for (i=0;i<5;++i) {
[self drawSolidRectangleWithColor:0 x1:(i*48) y1:57
x2:9+(i*48) y2:64];
}
for (i=0;i<20;++i) {
if (displayText[i].ready) {
[self drawSolidRectangleWithColor:0
x1:displayText[i].pixCol
y1:displayText[i].pixRow
x2:(displayText[i].pixCol)+displayText[i].areaLn-2
y2:(displayText[i].pixRow)+displayText[i].areaHt-2
];
[self setFont:displayText[i].font];
[self setPixelCursorX:displayText[i].pixCol
y:displayText[i].pixRow];
[self sendLCDdata:[displayText[i].data cString]];
//[NSThread sleepUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.001]];
usleep(1000); //Delay 0.001 seconds to not overrun the display
displayText[i].ready = FALSE;
}
}
prevMenu = currentMenu;
}
prevMenu = currentMenu;
//[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
usleep(100000); //Delay 0.1 seconds to give control to other threads
[pool2 release];
}
[pool release];
}
--
Fight Spam! Join CAUCE! ==
http://www.cauce.org/
_______________________________________________
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.