Hi folks we do hope you might help. I am trying to produce an anagram checker to have an apple iphone application. What I wish to do would be to have the ability to have a lengthy string of maximum 81 letters after which take a look against a thing list to locate all possible permutations associated with a length.

I have determined how to get this done around the simulator, however when I run this around the apple iphone it's very slow, taking around 90 seconds to loop car db (about 110000 rows). I checked Instruments also it does not show any memory leaks. However, if I personally use Object Allocations it's obvious that running the query produces an enormous allocation for CFString that drains anything else. This immediately runs up 3.09 Megabytes underneath the overall bytes column. (Within the code below, I have removed out all the anagram checking code when i desired to identify that which was leading to the issue. So that all this may at the moment is loop with the db with no output).

//create query
    NSString *querySQL2 = @"SELECT name FROM table ";

    sqlite3_stmt *statement2;
    const char *query_stmt2 = [querySQL2 UTF8String];



    sqlite3_prepare_v2(contactDB, query_stmt2, -1, &statement2, NULL);


    //loop through all rows of database
    while (sqlite3_step(statement2) == SQLITE_ROW)
    {
        NSString *laststring = [[NSString alloc] initWithUTF8String:
                          (const char *) sqlite3_column_text(statement2, 0)];



        [laststring release];
        }


    sqlite3_finalize(statement2);
   sqlite3_close(contactDB);

    }

It appears apparent in my experience that the development of 'laststring' below is exactly what is drawing up all of the memory. So why do after i put [laststring release] in the finish from the while loop it seems to possess no effect? I have run this code with and without delivering and also the same volume of memory can be used up. I have also attempted wrapping an autorelease around it which also didn't have effect.

I have read other queries on looping through SQLite. A number of them recommended indexing but I am unsure this can save me quite a lot of time with this particular problem. Also should i be searching all possible permutations from the large string of 81 letters, I am speculating that a minimum of 50% from the word list will have to be checked through anyway.

Any suggestions regarding how to keep CFString lower? Thank you Dork

So why do you alloc the NSString within the while() loop?

while(sqlite3_step(compiledStatement) == SQLITE_ROW) 
      {
      NSString *laststring = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement2, 0)];    
      // do something with laststring
      }

would suffice would it not?