1
votes

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.

also i have tried Xcode profiler for check memory leaks but no memory leaks found.

how can i resolve this issue?

thanks in advance.

2
You are going to have to post some codeDancreek
i faced same situation the last option i opt was that i controller number of threads when like up to 5 threads i sued to create and when those 5 threads got completed i create 5 new threads.Leena

2 Answers

1
votes

Instruments may not see all memory leaks especially if you are calling some C code as you are by passing the retaining functions.

It's hard to give you an answer without knowing what your thread contains but you may want to check your code for unreleased object / mis-deallocated / destroyed objects.

You should also check that you are not creating a whole bunch of threads (NSThread) and that they are correctly releasing their contents after termination.

By the way, your app shouldn't terminate when receiving a memory warning, it's a normal message coming from the OS. Check your deallocation when viewWillUnload / didReceivedMemoryWarning functions are called.

You should also try to create memory warning manually using the simulator

1
votes

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.

A second advice would be to use Instruments and Allocations, to see what exactly takes up your memory. Probably you have some object being retained and not released when it should be. This post is AMAZING when it comes to this http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/ and you might also find some useful info here http://www.cimgf.com/2008/04/02/cocoa-tutorial-fixing-memory-leaks-with-instruments/

Otherwise... you need to post more details.

Good luck!