• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: has exited due to signal 10 (SIGBUS).
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: has exited due to signal 10 (SIGBUS).


  • Subject: Re: has exited due to signal 10 (SIGBUS).
  • From: Brendan Younger <email@hidden>
  • Date: Thu, 16 Dec 2004 23:52:08 -0600

There are a few things wrong with your code. I've placed comments at the appropriate places. There are a lot of problems with the code below and they come from not really understanding memory management in Cocoa. Do not write any more code until you fully understand the articles at <http://www.stepwise.com/StartingPoint/Cocoa.html> under "Cocoa Basics".

On Dec 16, 2004, at 11:20 PM, Amit Kumar(R&D) wrote:

Thnks for reply.

Ok, I am sending the snippet of my code.


Code written in Handler.m file.

-(void)fillPProductList{
	//NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init];
	unsigned long thePID = 0;
	int val;
	int pc = [profile count];

	pProductDict = [[NSMutableDictionary alloc]init];
	QpmPublicationController *opc =[QpmPublicationController alloc];

Never do this. ALWAYS call an initialization method. Assuming QpmPublicationController's designated initializer is "init", call [[QpmPublicationController alloc] init].


	for(val=0 ; val < pc ; val++) //profile contains the product ID
	{
		QpmPublicationProduct *abc = [QpmPublicationProduct alloc];

Same complaint here as above. However, here you do NOT need to initialize the variable since you are setting it below. As it is, you're leaking memory.


		thePID =  [[profile objectAtIndex:val] unsignedLongValue];
		abc = [opc getPublicationProductInfo: thePID];

Here you're setting the "abc" variable, so the previous "[QpmPublicationProduct alloc]" is worthless.


		[pProductDict setObject: abc forKey:[NSNumber numberWithInt:
thePID]];

[abc release];

This is wrong. You do not own the object returned by "[opc getPublicationProductInfo: thePID]" and therefore, you should not release it.


	}
	[opc release];
}
Note: If I comment the for loop then Application does not get crashe.

//Code written in QpmPublicationController.m file.

-(QpmPublicationProduct*) getPublicationProductInfo:(unsigned long) thePPID
{
NSString *fpath = @"../PublicationProducts/";

This is bad form. I hope you don't ship code containing this line. The current directory can change at any time, so the "../" can refer to any directory. If you want to get the path of a specific resource, use the NSBundle methods.


	fpath = [fpath stringByAppendingString: [[NSNumber numberWithInt:
thePPID] stringValue]];
	fpath = [fpath stringByAppendingString:@".xml"];

The previous three lines can be simplified to: "fpath = [NSString stringWithFormat:@"%@/PublicationProducts/%d.xml", path_to_app_folder, thePPID]".


	QpmXMLParsingHelper* aHelper = [QpmXMLParsingHelper alloc]  ;
	QpmPublicationProduct* aPP = [QpmPublicationProduct alloc] ;

Again, never just call +alloc. ALWAYS call an initialization method. Also, you should NOT be setting "aPP" here since you'll be setting it later.


	aPP = [aHelper parseXMLFile:fpath forObject:[QpmPublicationProduct
class]];

Here you overwrite the value of "aPP" and hence leak the object pointed to by "aPP".


	return aPP;
}

Can't wait for the next version of Quark...

Brendan Younger

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: has exited due to signal 10 (SIGBUS).
      • From: Steven Kramer <email@hidden>
References: 
 >RE: has exited due to signal 10 (SIGBUS). (From: "Amit Kumar(R&D)" <email@hidden>)

  • Prev by Date: Re: has exited due to signal 10 (SIGBUS).
  • Next by Date: Re: has exited due to signal 10 (SIGBUS).
  • Previous by thread: Re: has exited due to signal 10 (SIGBUS).
  • Next by thread: Re: has exited due to signal 10 (SIGBUS).
  • Index(es):
    • Date
    • Thread