• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Caching variables in ManagedObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Caching variables in ManagedObjects


  • Subject: Re: Caching variables in ManagedObjects
  • From: Jim Correia <email@hidden>
  • Date: Wed, 22 Nov 2006 19:58:27 -0500

On Nov 22, 2006, at 7:18 PM, Alexander Griekspoor wrote:

Which suggested me to add the following code:

- (void)didTurnIntoFault{
	[cachedPreferredName release];

	[super didTurnIntoFault];
}

However now I started to have strange crashes in kvoobservers etc. Only now I realise what was going on. My mistakes were based on what I think is my misinterpretation of how custom MO classes are used. However I would like to hear if that's indeed true or whether I do something wrong elsewhere.

I think the reason for the crashes is that I don't nil the pointer to cachedPreferredName in the didTurnIntoFault message. I thought the MO object would be deallocated upon faulting (and thus the caches removed) and I would receive a new object the moment it would be unfaulted again.

No. An object can be turned into a fault without it being deallocated. Any iVars you release in -didTurnIntoFault should be set to nil.


Second, if so, wouldn't it make more sense then to let the cache stay alive even after faulting (eventually cleaning up in dealloc instead)?

No. Please refer to what the documentation has to say:

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ Articles/cdManagedObjects.html

	You should typically not override the dealloc method to clear
	transient propertied and other variables. Instead, you should
	override didTurnIntoFault. didTurnIntoFault is invoked automatically
	by Core Data when an object is turned into a fault and immediately
	prior to actual deallocation. A managed object may be turned into a
	fault specifically to reduce memory overhead (see “Reducing Memory
	Overhead”), so it is important to ensure that you properly perform
	clean-up operations in didTurnIntoFault.


The only question would be: is it likely/possible, that the faulted object has changed (and thus turned the caches outdated) in the period the MO has been faulted?

One reason an object may be turned into a fault is that you are refreshing it, in which case computed values which have been cached may no longer be valid.


I strongly have the feeling I start to get it but not fully grasp yet the details of what is going on here, any help/advise on the topic would be greatly appreciated!

In addition to reading the API documentation, be sure to read the programming guides and conceptual overviews. After you've read them and have worked with CoreData for awhile, go back and read them again. (There are many things I've picked up from the docs that didn't sink in on the first or second reading.)


Jim

_______________________________________________

Cocoa-dev mailing list      (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins (at) lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Caching variables in ManagedObjects
      • From: Alexander Griekspoor <email@hidden>
References: 
 >Caching variables in ManagedObjects (From: Alexander Griekspoor <email@hidden>)

  • Prev by Date: Re: Replacing Info.plist programmatically
  • Next by Date: Re: Caching variables in ManagedObjects
  • Previous by thread: Caching variables in ManagedObjects
  • Next by thread: Re: Caching variables in ManagedObjects
  • Index(es):
    • Date
    • Thread