• 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: MyShadow was deallocated while key value observers...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MyShadow was deallocated while key value observers...


  • Subject: Re: MyShadow was deallocated while key value observers...
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 27 Jun 2014 23:25:33 -0500

On Jun 27, 2014, at 3:21 PM, Leonardo wrote:

> While the user moves the selection within an NSTextView, I show on the UI
> the values of the current textShadow: offsetX, offsetY and blur. In each
> textField on IB, I bind, e.g.
>
>   oObjsArrayController.selection.textShadow.offsetX
>
> So, in the textView's method textViewDidChangeSelection I do
>   attr = [self.textStorage attributesAtIndex:loc effectiveRange:effRange];
>   self.textShadow = [attr objectForKey:MyShadowAttributeName];
>
>
> textShadow is never retained. It's just a pointer that I set to nil or to
> the current selected shadow, as above, just to show the current selected
> shadow values. On the header, it looks
>
>   @property (nonatomic, assign) MyShadow      *textShadow;
>
> Sometimes, when I create a new shadow or I release the textView I get this
> bug:
>
>   MyShadow was deallocated while key value observers were still registered
>   with it...
>
> Why? I can't find a solution to this bug.

Why don't you make the property retain?  What harm would it cause?

Anyway, the problem is that the object pointed to by your textShadow property can be deallocated while you're still pointing to it (precisely because your reference is __unsafe_unretained).

You get told that the attributes have potentially changed after the fact.  In the case where the text view removed the MyShadowAttribute (perhaps because that range of text was deleted), it has presumably been deallocated before the call to -textViewDidChangeSelection:.

Since your property hasn't been changed to no longer point to it, the key-value observers implicit in the binding have not been told to update their observations.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: MyShadow was deallocated while key value observers...
      • From: Leonardo <email@hidden>
References: 
 >MyShadow was deallocated while key value observers... (From: Leonardo <email@hidden>)

  • Prev by Date: Re: MyShadow was deallocated while key value observers...
  • Next by Date: Re: MyShadow was deallocated while key value observers...
  • Previous by thread: Re: MyShadow was deallocated while key value observers...
  • Next by thread: Re: MyShadow was deallocated while key value observers...
  • Index(es):
    • Date
    • Thread