1

I am getting the error:

"-[CFString retain]: message sent to deallocated instance"

when returning [NSString stringWithFormat:@"%d is reserved for future use",reportID]; to objectValueForTableColumn in an NSOutlineController.

But when the literal [@"This is a test" copy] is used all is well.

I thought that stringWithFormat would return a pointer that would be retained by the receiver just like [@"This is a test" copy] does but I seem to be misunderstanding stringWithFormat.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
oregonduckman
  • 389
  • 2
  • 13
  • You need to supply more context in order for people to help you without guessing. Edit the question and show the context of your `stringWithFormat` call. Explain why you are copying a literal string. Also indicate what sort of memory management you are using. With those details somebody may be able to help. – CRD Feb 02 '16 at 01:30
  • Using ARC. The method in questions returns an NSMutableArray of strings which are used to respond to NSOutlineViewDataSource protocol methods - - outlineView:child:ofItem: and objectValueForTableColumn. A few of the strings are created using stingWithFormat and it is those strings that are causing the "-[CFString retain]: message sent to deallocated instance" error. I changed the stingWithFormat construct with the literal copy as a debugging step but it is my understanding that [@"Test" copy] and [NSString stringWithFormat:@"%d Test",10]; should both return freshly allocated NSStrings. – oregonduckman Feb 02 '16 at 18:48
  • did you ever find out the solution for this? – zaitsman Apr 30 '21 at 02:17
  • I am sorry but it was so long ago I can't remember. I hope you are able to find an answer. – oregonduckman May 01 '21 at 04:58

0 Answers0