views:

515

answers:

2
+1  A: 

This is just a guess, as not all of the code is there. In your init method for the Transaction class, do you make sure to retain the strings? (category and description).

The thing that stands out to me is that you initialize the Transaction, then release the categoryString immediately after. If you're not retaining the string, then this could be the source of your crash.

On a side note, you are leaking memory. Here:

NSString *descriptionString = [[NSString alloc] init];
descriptionString = descriptionField.text;

descriptionString is pointing to a newly allocating string, only to be reassigned to an existing string, so the first string is leaked. You should change this to:

NSString *descriptionString;
descriptionString = descriptionField.text;

or more simply:

NSString *descriptionString = descriptionField.text;
bobDevil
i have the strings set up as different properties and I'm using copy, maybe I should use retain? @property (nonatomic, copy) NSString *description;as far as the memory leak, thanks, I have been messing with releases because in researching this I saw that a segmentation a fault may be caused by over releasing an object.trying a retain now
nickthedude
I think that solved the issue although the program still is not working quite right but I think that was it. thanks
nickthedude
the property declarations only effect the getters and setters, not the init function, so the problem could have still existed if you didn't use the setter function in your init method. Glad my solution helped.
bobDevil
i was using the setter in the init method
nickthedude
+1  A: 

This is wrong:

NSIndexPath *indexPath = [[NSIndexPath alloc] init];
indexPath = [self.categoryTableView indexPathForSelectedRow];

NSInteger selectedCategory = indexPath.row;
[indexPath release];

You're instantiating an empty NSIndexPath and then overwriting the reference to it. The release on the last line is sent to an entirely different object returned by the table view. The object you create is never used and never released.

This will work:

NSIndexPath *indexPath = [self.categoryTableView indexPathForSelectedRow];
NSInteger selectedCategory = indexPath.row;

You're not creating an NSIndexPath object, so you have no responsibility to release it.

(your unnecessary release is causing the index path instance to be prematurely deallocated. When Apple's code tries to release the object, it no longer exists, and the app crashes)

grahamparks
thanks man, that worked a treat. i had a hell of a time trying to figure that thing out and it surprisingly worked, the first time you tried it at least, but yeah it was broken. thanks a lot the code seems to be putting along perfectly now thanks to both answers here, i wish I could give two answers the green check but only one allowed. Now im off to try and solve more problems.:)
nickthedude