为什么Cocoa偶尔返回一个空字符串? [英] Why does Cocoa return an empty string occasionally?

查看:86
本文介绍了为什么Cocoa偶尔返回一个空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中有一些代码看起来像这样:

  char * hash =(char *)sqlite3_column_text get_bookmark,0); 
NSString * postHash = [NSString stringWithUTF8String:hash];

我从来没有见过不是工作。我的大多数用户没有遇到问题(据我所知)。但是我发现对于某些用户来说 postHash 是一个空字符串( @ p>

任何人都可以解释为什么?



有些情况/猜测:


$ b b

这似乎只发生在越狱手机上。他们有什么不同吗?我认为通常有更少的内存可用。



postHash 在表格单元格中使用,偶尔会被看到填充正确所以我有理由相信数据库调用应该工作。事实上,如果数据库也有一个空字符串,这是因为一个非常相似的代码段,所以问题仍然存在。



hash 当然返回非NULL值。如果我强制在这里的NULL,应用程序崩溃。类似地, postHash 不是 nil ,因为这也会崩溃的应用程序(同样的原因)。



我认为这可能是内存相关的。如果该方法试图在 -didReceiveMemoryWarning 之前分配太多内存,可以调用会发生什么?我知道,在某个时候,Springboard弹出的应用程序。但是Cocoa是否可能返回一个空字符串而不是预期值?我听说过几个报告,据我所知,只能是一个空字符串存在的地方,应该存在更长的时间。



任何其他猜测,理论或想法欢迎。

解决方案


但我发现 postHash 对于某些用户来说是一个空字符串( @)。



任何人都可以解释为什么?


因为 hash 空字符串( hash [0] =='\0')。


I have some code in my application that looks something like this:

char *hash = (char*) sqlite3_column_text(get_bookmark, 0);
NSString* postHash = [NSString stringWithUTF8String:hash];

This works for me every time; I've never seen it not work. Most of my users do not experience problems (as far as I know). However I find that postHash is an empty string (@"") for some users some of the time.

Can anyone explain why?

Some more context/speculation:

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?

postHash is used in a table cell and is occasionally seen to be populated correctly so I'm reasonably confident that the database call should 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.

hash is certainly returning with a non-NULL value. If I force a NULL here, the app crashes. Similarly, postHash is not nil as that would also crash the app (for the same reason).

I am thinking that this is possibly memory related. If the method tries to allocate too much memory before -didReceiveMemoryWarning 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.

Any other speculation, theories or ideas welcome.

解决方案

However I find that postHash is an empty string (@"") for some users some of the time.

Can anyone explain why?

Because hash is an empty string (hash[0] == '\0').

这篇关于为什么Cocoa偶尔返回一个空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆