4

I have a function that is creating a variable, but not deallocating it. It passes this object on with a message to another function that deals with the memory management.

My question is how do I suppress the static analyzer warning for what XCode thinks is an over-retained variable? I thought I could use NS_RETURNS_RETAINED for the function that is creating it, but that doesn't work. I wonder if it has something to do with the fact that the variable is passed on through a message?

Shaun Budhram
  • 3,690
  • 4
  • 30
  • 41
  • Could you provide a bit more detail of the functions involved, maybe with some (pseudo)code? – Yuji Jun 28 '10 at 19:09
  • @Yuji Think about a C memory database, that takes `void *` memory pointers. I want to store a `CFDictionaryRef` there but to make sure that it stays alive, I have to call `CFRetain` and analyzer complains that this is a leak but it's not, I can still get a references to the dict at any time and I will also do a `CFRelease` on it, when it is removed from that memory database. – Mecki Feb 23 '16 at 18:53

2 Answers2

4

You can suppress the memory warning by doing the following:

  1. Select target
  2. Select build phase
  3. Select complile sources
  4. Find file for which you want to suppress warning.
  5. Set compiler flags to following by double clicking on it:

    -w -Xanalyzer -analyzer-disable-checker

Abhay Singh
  • 586
  • 5
  • 11
0

I don't recommend that the warnings are suppressed because they are there for a good reason. Well-coded applications have lots of testing with little or no memory leaks.

However, you can disable the warnings in Xcode 4 by going to the Xcode inspector, and typing "memory" in the search box. There will be a column with a relevant option. On the right, there is an option that you can select.

alexyorke
  • 4,224
  • 3
  • 34
  • 55