Collection was mutated while being enumerated

  • Since installing Leopard I'm seeing the following appear appear in the
    console: "*** Collection <NSCFDictionary: 0x5e2e540> was mutated while
    being enumerated."

    I imagine this was something happening in the code before Leopard but
    Leopard started logging it. Is there by any chance a breakpoint I can
    set to catch where this is occurring? Would be handy.

    -Phil
  • On Oct 29, 2007, at 2:02 PM, Philip Dow wrote:

    > Since installing Leopard I'm seeing the following appear appear in
    > the console: "*** Collection <NSCFDictionary: 0x5e2e540> was mutated
    > while being enumerated."
    >
    > I imagine this was something happening in the code before Leopard
    > but Leopard started logging it. Is there by any chance a breakpoint
    > I can set to catch where this is occurring? Would be handy.

    Several ways; the first way is to link against Leopard. The second way
    is to set the user default: NSFastEnumerationShouldThrow=YES.

    Then break on objc_exception_throw.

    --corbin
  • On Oct 29, 2007, at 3:02 PM, Philip Dow wrote:

    > Since installing Leopard I'm seeing the following appear appear in
    > the console: "*** Collection <NSCFDictionary: 0x5e2e540> was mutated
    > while being enumerated."
    >
    > I imagine this was something happening in the code before Leopard
    > but Leopard started logging it. Is there by any chance a breakpoint
    > I can set to catch where this is occurring? Would be handy.

    Break on "objc_exception_throw" with no quotes or parentheses.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • There were a number of performance improvements in Obj-C 2.0
    One of them was loop optimization.
    In order for this optimization to work, you can't change (mutate) a
    collection while iterating through it with an enumerator.
    I.E.: you can't add/delete items in an array or dictionary (change
    the count) while looping through it - that's what the message below
    is saying.

    On Oct 29, 2007, at 5:02 PM, Philip Dow wrote:

    > Since installing Leopard I'm seeing the following appear appear in
    > the console: "*** Collection <NSCFDictionary: 0x5e2e540> was
    > mutated while being enumerated."
    >
    > I imagine this was something happening in the code before Leopard
    > but Leopard started logging it. Is there by any chance a breakpoint
    > I can set to catch where this is occurring? Would be handy.
    >
    > -Phil
  • >
    > Then break on objc_exception_throw.

    Brilliant. Thanks very much.

    -Phil
  • On 10/29/07 2:56 PM, Corbin Dunn said:

    >> Since installing Leopard I'm seeing the following appear appear in
    >> the console: "*** Collection <NSCFDictionary: 0x5e2e540> was mutated
    >> while being enumerated."
    >>
    >> I imagine this was something happening in the code before Leopard
    >> but Leopard started logging it. Is there by any chance a breakpoint
    >> I can set to catch where this is occurring? Would be handy.
    >
    > Several ways; the first way is to link against Leopard. The second way
    > is to set the user default: NSFastEnumerationShouldThrow=YES.

    NSFastEnumerationShouldThrow, eh?  0 hits with Google, 0 hits in Xcode's
    doc viewer.  :)  Are there other new secret debugging aids in 10.5?

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada
  • On Oct 31, 2007, at 2:51 PM, Sean McBride wrote:

    > On 10/29/07 2:56 PM, Corbin Dunn said:
    >
    >>> Since installing Leopard I'm seeing the following appear appear in
    >>> the console: "*** Collection <NSCFDictionary: 0x5e2e540> was mutated
    >>> while being enumerated."
    >>>
    >>> I imagine this was something happening in the code before Leopard
    >>> but Leopard started logging it. Is there by any chance a breakpoint
    >>> I can set to catch where this is occurring? Would be handy.
    >>
    >> Several ways; the first way is to link against Leopard. The second
    >> way
    >> is to set the user default: NSFastEnumerationShouldThrow=YES.
    >
    > NSFastEnumerationShouldThrow, eh?  0 hits with Google, 0 hits in
    > Xcode's
    > doc viewer.  :)  Are there other new secret debugging aids in 10.5?

    I thought the exceptions would come for free (i.e. always be turned
    on).  See the notes in the "Fast Enumeration" section here:

    <http://developer.apple.com/leopard/overview/objectivec2.html>

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • >> NSFastEnumerationShouldThrow, eh?  0 hits with Google, 0 hits in
    >> Xcode's
    >> doc viewer.  :)  Are there other new secret debugging aids in 10.5?
    >
    >
    > I thought the exceptions would come for free (i.e. always be turned
    > on).  See the notes in the "Fast Enumeration" section here:
    >
    > <http://developer.apple.com/leopard/overview/objectivec2.html>

    Yes, they will come for free, but you must link against Leopard (you
    must have missed my original email that stated this). Foundation uses
    Fast Enumeration when it can (ie: not just 'for .. in' statements). We
    discovered that there are some bad apps out there that would crash
    because of this. For binary compatibility, we can't have people's apps
    crashing, and instead log a warning. When the link on Leopard, they
    will start raising exceptions.

    --corbin
  • >>> Since installing Leopard I'm seeing the following appear appear in
    >>> the console: "*** Collection <NSCFDictionary: 0x5e2e540> was mutated
    >>> while being enumerated."
    >>>
    >>> I imagine this was something happening in the code before Leopard
    >>> but Leopard started logging it. Is there by any chance a breakpoint
    >>> I can set to catch where this is occurring? Would be handy.
    >>
    >> Several ways; the first way is to link against Leopard. The second
    >> way
    >> is to set the user default: NSFastEnumerationShouldThrow=YES.
    >
    > NSFastEnumerationShouldThrow, eh?  0 hits with Google, 0 hits in
    > Xcode's
    > doc viewer.  :)  Are there other new secret debugging aids in 10.5?

    Yes, there are lots. I recommend taking a moment to read the AppKit
    release notes, as there are several new debugging secrets mentioned
    there:

    http://developer.apple.com/releasenotes/Cocoa/AppKit.html

    Granted, this one isn't there, but linking against Leopard would cause
    it to raise an exception and be easily debuggable.

    -corbin
  • > There were a number of performance improvements in Obj-C 2.0
    > One of them was loop optimization.
    > In order for this optimization to work, you can't change (mutate) a
    > collection while iterating through it with an enumerator.
    > I.E.: you can't add/delete items in an array or dictionary (change
    > the count) while looping through it - that's what the message below
    > is saying.

    It's always been very dangerous to modify a collection while
    enumerating it. It's just the logging that's new in Leopard.
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today