Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5966449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:48:07+00:00 2026-05-22T19:48:07+00:00

Does a setter of a CoreData-attribute retains? or copies the value or what does

  • 0

Does a setter of a CoreData-attribute retains? or copies the value or what does the setter? I want to know if I have to (auto-)release the value that I am putting into the setter.

I’ve done some quick tests on that. Assuming the following model:

+----------+
| Class A  |
+----------+
| v :int32 |
+----------+

The generated ManagedObject then looks like this:

//A.h
@interface A :  NSManagedObject  
{
}
@property (nonatomic, retain) NSNumber * v;
//...

//A.m
@implementation A 
@dynamic v;
...

Ok, the property is marked with retain, so if I set a NSNumber to v the NSNumber should be retained. but it is not (I think). I did the following:

A *a = ... ;
NSNumber *retainCheck = [[NSNumber alloc] initWithInt:23];
NSLog(@"retainCheck1: %i",[retainCheck retainCount]);
a.v = retainCheck;
NSLog(@"retainCheck2: %i",[retainCheck retainCount]);
NSLog(@"retainCheck3: %i",[a.v retainCount]);
NSLog(@"pointer1: %#x",retainCheck);
NSLog(@"pointer2: %#x",a.v);

this produces the following output:

retainCheck1: 1
retainCheck2: 1
retainCheck3: 1
pointer1: 0x62f068
pointer2: 0x62f068

Both NSNumbers are the same NSNumber-instance (same pointer-value -> so it does no copy or sth like that) and the NSNumber doesn’t seem to be retained by the setter.

Am I doing sth. wrong in my test? or is the behaviour of NSManagedObject-setters not the same as described in the header?

edit: I am calling retainCount because I wanted to observer a retain not release or autorelease. The observed behaviour can be explained by the flyweight-pattern linked by Abizern

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:48:07+00:00Added an answer on May 22, 2026 at 7:48 pm

    Firstly – Don’t worry about how Core Data manages it’s properties – As long as you release the objects that you own, that’s what matters.

    Secondly – you’re testing using NSNumber. NSNumber is a strange class that adopts the flyweight design pattern, so getting the retainCount of an NSNumber isn’t going to tell you anything about how Core Data manages its objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that does <Style TargetType=ListViewItem> <Setter Property=XX Value=true /> </Style> This
Does anyone have a nice solution for GalleryView when I want to display photos
Does anyone have some code that will take a TimeZoneInfo field from .NET and
Does Komodo support getter/setter auto generation a la NetBeans or Eclipse? If so how
Does anyone know of a way to add additional attribute types to the @property
I have a static setter that is used to set all instances of MyClass:
Does anyone know where to find a list of controls that you can set
As we know Silverlight does not allow private reflection. Still, I have a public
Does anyone know how to add a border to a Dockpanel. i have this:
I have a custom usercontrol that does a little animation on a DispatcherTimer tick,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.