instanz von NSInvocation als "erstes" argument von sich selbst setzen erlaubt?

  • instanz von NSInvocation als "erstes" argument von sich selbst setzen erlaubt?

    Ist also das hier erlaubt oder entsteht dadurch eine circular reference und das objekt wird somit nie released?

    Quellcode

    1. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[target methodSignatureForSelector:selector]];
    2. [invocation setSelector:selector];
    3. [invocation setTarget:target];
    4. [invocation setArgument:&invocation atIndex:2];
    5. [invocation setArgument:&arg2 atIndex:3];
    6. [invocation retainArguments];
  • Gemäß Dokumentation wird der Parameter kopiert.
    https://developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSInvocation_Class/Reference/Reference.html#//apple_ref/occ/instm/NSInvocation/setArgument:atIndex:
    This method copies the contents of buffer as the argument at index.
    (...)
    When the argument value is an object, pass a pointer to the variable (or memory) from which the object should be copied


    Deine eigentliche NSInvocation Instanz ist davon also völlig unbeeindruckt.
    Und da es eh nur Kopien seiner Argumente vorhält, kümmert es sich so oder so um die Ownership der Objekte.

    Ich sehe dort keine circular reference.
    «Applejack» "Don't you use your fancy mathematics to muddle the issue!"

    Iä-86! Iä-64! Awavauatsh fthagn!

    kmr schrieb:

    Ach, Du bist auch so ein leichtgläubiger Zeitgenosse, der alles glaubt, was irgendwelche Typen vor sich hin brabbeln. :-P
  • nein, so funktioniert das sicher nicht!
    es wird nur die speicheradresse kopiert (im falle eines objektes).
    mittels retainArguments werden dann die objekte retained und nicht kopiert.
    ansonsten könntes man ja keine objekte übergeben dessen klasse copy nicht implementiert hat (zb auch NSInvocation).

    aber egal. ich hätte das benötigt um NSInvocationOperation aufzubohren sodass man mehrere obejkte übergeben kann und das erste immer die invocation selbst ist (zb um zu prüfen ob sie gecancelt wurde etc).

    habs jetzt aber so gelöst dass ich direkt eine subclass von NSOperation gemacht habe ;)