English 中文(简体)
在 ios 中使用 NSTread 时“ 收到的内存警告”
原标题:"Received memory warning" when using NSThread in ios

I am developing iPhone App. i am using NSThread for continuous calling of function which contains C++ code. when i use NSThread or dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{ Function calling } then it gives me "Received memory warning" warning after 5min and crash the application. but when i run this function on main thread/Queue then it works perfactly.

我还尝试过 Xcode 配置程序检查内存泄漏, 但没有发现内存泄漏 。

我如何解决这个问题?

提前感谢。

问题回答

仪器可能不会看到所有内存泄漏,特别是如果你正在通过保存功能来呼唤某些C代码。

在不知道你的线条内容的情况下很难给你答案,但你也许想检查一下未释放的物体/误分/销毁的物体的代码。

您还应该检查您是否正在创建一整串线索( NSThread ), 并且这些线索在终止后正确释放内容 。

顺便说一句, 您的应用程序在收到内存警告时不应终止, 它是一个来自 OS 的普通信件 。 当调用 < code> view willunload / < code> / < didReceivedMemory Warning 函数时, 请检查您的交易位置 。

您也应该尝试使用模拟器手动创建内存警告

I had a somewhat similar problem using a NSOperationQueue on a background thread. Assuming you have already declared you mandatory NSAutoreleasePool in the function, you could try to allocate/release the objects yourself and don t use autorelease unless necessary, to make sure the memory is freed right on time.

第二个建议是使用工具与配置, 查看您记忆中的确切内容。 可能您有一些东西被保留了, 但应该时不会释放。 当涉及到这个 < href=" http://www. friday.com/bbum/2010/10/17/ when- is- a-leak- not- a-leak- leak- unt- a-leak- liapshot- shaps- heapshot- 分析- to- find- und- unesirable- memory- grow/" rel= nofol ", http://www. cimff.com/2008/04/ coa- tumental- fixing- leaks- with- intrestruments/ " rel-leak- leak- not- a-leak- useing- hiapshot- assury- find- es- emor- gref- grow- fol- fol- fol- a fol- fol- folping.

否则... 你需要发布更多细节

祝你好运!





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签