Newbie probably not retaining himself to well...
Newbie probably not retaining himself to well...
- Subject: Newbie probably not retaining himself to well...
- From: Alexander Griekspoor <email@hidden>
- Date: Thu, 20 Jun 2002 08:28:17 +0200
Hi all,
Here's another newbie asking for help. I know there are a lot of newbie
request lately, but please know that all the help is appreciated enormously!
Guess it's the downside of an expanding community ;-) I'm just getting
started but I'm so excited about the things I can do now, that I never could
before. Thanks Apple and thanks all developers writing tutorials, sample
code and helping newbies getting started...
So back to work, I'm kind of stuck writing this new program with which I
want to track some experiments I'm doing. The basic idea is that for every
experiment and "Experiment" object is created. After creation I put the
current date into the variable startdate via the setStartdate method (all
the relevant code is listed below. Everything works fine, and no complaints
thus far. Now I have a tableView which among others has a collumn "time". I
want to display the time the experiment started here. I don't want to do
this by directly putting the startdate with a formatter in there though,
because I want to display other times to in there. So I thought of creating
the time as a string myself directly when the startdate was set too. The
problem is that when I now request the starttime variable, as the tableView
does, 9 out 10 times the program crashes, giving sigbus 10 or 11 errors, and
that one other time, the tableView shows that the contents of the starttime
string is rubish.
As the NSLog shows, the starttime variable is set correctly within the
setStartdate method, so I guess I have a classical retain/release problem
here. I don't see the solution however... Don't I generate the variables
correctly in the init method? (by the way, it is deallocated in the dealloc
method). When do I have to give a retain or copy command or when/where do I
have to set the variable to autorelease? Any advice or help is highly
appreciated...
Alex
/* Inititalization of Experiment object*/
- (id)init
{
self = [super init];
(NSCalendarDate *) stopdate = [[NSCalendarDate alloc] init];
(NSString *) starttime = [[NSString alloc] init];
(NSString *) stoptime = [[NSString alloc] init];
NSLog(@"I'm Alive!");
// etc.
/* set the startdate and immediately afterwards the "formatted" time
string*/
- (void)setStartdate: (NSCalendarDate*) value
{
[startdate autorelease];
startdate = [value copy];
if([startdate minuteOfHour] < 10){
starttime = [NSString stringWithFormat: @"%d:0%d",
[startdate hourOfDay], [startdate minuteOfHour]];
}
else{
starttime = [NSString stringWithFormat: @"%d:%d",
[startdate hourOfDay], [startdate minuteOfHour]];
}
NSLog(@"%@", starttime);
}
/* accessor method for starttime */
- (NSString *) starttime
{
return starttime;
}
/* Log after creating a new object and requesting the starttime method
afterward*/
2002-06-20 08:05:00.397 LabAssistant[1024] I'm Alive!
2002-06-20 08:05:00.455 LabAssistant[1024] 8:05
LabAssistant has exited due to signal 11 (SIGSEGV).
*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
E-mail: email@hidden
Web:
http://go.to/neefixlab
*********************************************************
The requirements said: Windows 2000 or better.
So I got a Macintosh.
*********************************************************
_______________________________________________
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.