Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does Cocoa return an empty string occasionally?
    primarykey
    data
    text
    <p>I have some code in my application that looks something like this:</p> <pre><code>char *hash = (char*) sqlite3_column_text(get_bookmark, 0); NSString* postHash = [NSString stringWithUTF8String:hash]; </code></pre> <p>This works for me every time; I've never seen it <em>not</em> work. Most of my users do not experience problems (as far as I know). However I find that <code>postHash</code> is an empty string (<code>@""</code>) for some users some of the time.</p> <p>Can anyone explain why?</p> <p>Some more context/speculation:</p> <p>This only seems to happen on jailbroken handsets. Is there anything different about them? I gather that there's usually less memory available. Anything else that could contribute here?</p> <p><code>postHash</code> is used in a table cell and is occasionally seen to be populated correctly so I'm reasonably confident that the database call <em>should</em> work. In fact, if the database also has an empty string it's because of a very similar piece of code so the question remains.</p> <p><code>hash</code> is certainly returning with a non-NULL value. If I force a NULL here, the app crashes. Similarly, <code>postHash</code> is not <code>nil</code> as that would also crash the app (for the same reason).</p> <p>I am thinking that this is possibly memory related. If the method tries to allocate too much memory before <code>-didReceiveMemoryWarning</code> can get called what happens? I know that, at some point, the Springboard ejects the app. But is it possible that Cocoa returns a null string here rather than the expected value? I've heard of a few reports that, as far as I can tell, can only have been caused by an empty string being present where something longer should have been present.</p> <p>Any other speculation, theories or ideas welcome.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload