Re: It doesn't work without the NSLog()... Why?
Re: It doesn't work without the NSLog()... Why?
- Subject: Re: It doesn't work without the NSLog()... Why?
- From: Тимофей Даньшин <email@hidden>
- Date: Wed, 29 Apr 2009 16:48:55 +0400
Why copy mutableRet when you just release it anyway? Instead, just
return it with an autorelease:
I do that because i return an immutable array. I always try to return
the types i promise to return in the declaration :)
To Kyle:
I looked at the -
intoArray:addItemFromTable:usingStatement:andSearchString:, but i
failed to find anything bad in there. Here is the code:
- (void) intoArray:(NSMutableArray *)mutableRet addItemFromTable:
(NSString *)table usingStatement:(sqlite3_stmt *)statement
andSearchString:(NSString *) searchString {
sqlite3_bind_text(statement, 1, [searchString
cStringUsingEncoding:NSUTF8StringEncoding], -1, SQLITE_TRANSIENT);
while (sqlite3_step(statement) == SQLITE_ROW) {
NSString *s = [NSString stringWithUTF8String:(char *)
sqlite3_column_text(statement, 0)];
int wid = sqlite3_column_int(statement, 1);
[mutableRet addObject:[WordIdAndDatabase makeWithId:wid word:s
andDatabaseName:table]];
}
}
And here is some more detailed description of the problem. The thing
is that i have a class called "Database" which is responsible for
communicating with my database. The Database class is controlled by a
DatabaseManager, which is a singleton... Any object in my application
wanting to get anything from the db calls the [DatabaseManager
sharedManager] and calls the methods it needs to call.
As I may have mentioned before, the app I am writing is a dictionary.
The user interface has an NSTableView and an NSTextField. As the user
types a searchword into the textfield, the app creates new
NSOperations that select the words beginning with the chars the user
has typed, from the database, and then i show them in the table view.
Again, all the interactions with the db are executed via the
DatabaseManager.
When the user hits enter or clicks on a cell with a word in it, we
select that word with the equivalent from the db and display that in a
different window.
And the thing is that when the NSLog line we talked above is not
there, the -selectWordsBeginningWith: method works fine only until the
user presses Enter or clicks a cell, i.e. until we get another class
connect to the database.
Again, with NSLog in place, it all works fine no mater how many
translations you open...
I would be really grateful for any hints to what the cause might be.
On Apr 29, 2009, at 4:32 PM, Graham Cox wrote:
On 29/04/2009, at 10:05 PM, Тимофей Даньшин wrote:
NSArray *ret = [mutableRet copy];
// NSLog(@"The number of items to be returned is: %i", [ret count]);
[mutableRet release];
return ret;
I don't see why your NSLog line should cause a problem, but your
memory management at the end of the function is wrong, so may have a
bearing on it.
Why copy mutableRet when you just release it anyway? Instead, just
return it with an autorelease:
return [mutableRet autorelease];
There is no need to copy a mutable array just so you can return it
as a non-mutable array - it is an array and its mutability is
invisible to the client of this code. As it stands you're leaking
the copy because it is never released.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden