I'm a little lost,
I have a NSMutableArray instance which gets released at the end of my IBAction. The problem is that if I do release it the program terminates with:
Now if I remove the release message everything is fine, but that raises the question: shouldn't I release the instances that I create? Heres the action as I have it; not finished .
The bold section causes the problem, if anyone could explain why this is happening I would much appreciate it! I've check the retainCount right before the release (it's 1), and no calls are being made to the instance after its release as far as I can see .
Edit: I could the code project if that would help, but this is pretty much it appart from a simple interface and a few methods like windowWillClose: etc.
Thanks a lot, you guys are always very helpful.
Mark.
I have a NSMutableArray instance which gets released at the end of my IBAction. The problem is that if I do release it the program terminates with:
[Session started at 2005-01-24 16:06:17 +0000.]
Executable Strip! has exited due to signal 10 (SIGBUS).
Now if I remove the release message everything is fine, but that raises the question: shouldn't I release the instances that I create? Heres the action as I have it; not finished .
Code:
#import "StripController.h"
@implementation StripController
- (IBAction)clean:(id)sender
{
int thisIndentationLevel = 0,
lastIndentationLevel = 1,
lineIndex, lineCount;
NSMutableArray *reformattedLines;
NSArray *unformattedLines;
NSMutableString *reformattedLine;
NSString *unformattedLine;
unformattedLines = [[[textView string]
componentsSeparatedByString: @"\n"] retain];
lineCount = [unformattedLines count];
reformattedLines = [NSMutableArray array];
for (lineIndex = 0; lineIndex < lineCount; lineIndex++)
{
thisIndentationLevel = 0;
// Begin the main formatting loop. Loops over each line in *textView and cleans
// the source to make it easier to read.
int i, c, substring = 0;
unformattedLine = [unformattedLines objectAtIndex: lineIndex];
for (i = 0, c = [unformattedLine length]; i < c; i++)
{
if ([unformattedLine characterAtIndex: i] != '>' &
[unformattedLine characterAtIndex: i] != ' ') break;
substring++;
}
for (i = 0; i < substring; i++)
if ([unformattedLine characterAtIndex: i] == '>')
thisIndentationLevel++;
// Make changes to the string and append the newly formatted line to the
// reformattedLines variable.
lastIndentationLevel = thisIndentationLevel;
}
// Update text in the *textView outlet.
[unformattedLines release];
[b][reformattedLines release];[/b]
[sender setEnabled: NO];
}
The bold section causes the problem, if anyone could explain why this is happening I would much appreciate it! I've check the retainCount right before the release (it's 1), and no calls are being made to the instance after its release as far as I can see .
Edit: I could the code project if that would help, but this is pretty much it appart from a simple interface and a few methods like windowWillClose: etc.
Thanks a lot, you guys are always very helpful.
Mark.