FROM : Nir Soffer
DATE : Mon Feb 25 21:49:45 2008
On Feb 21, 2008, at 18:22, Hank Heijink wrote:
> I have a document-based application, and my NSDocument subclass
> runs an experiment which amounts to invoking NSInvocations based on
> certain conditions. These NSInvocations retain their arguments, and
> the target of the NSInvocation is the NSDocument subclass. I need
> to record these invocations as well, so I made a class MVAction as
> follows:
>
> @interface MVAction : NSObject <NSCoding> {
> NSInvocation *action;
> double invocationTime;
> NSString *type;
> NSArray *arguments;
> }
>
> The type is a string representation of the selector used in the
> NSInvocation and the arguments are the arguments of the
> NSInvocation. I did it like this because you can't encode an
> NSInvocation, and I don't need the actual invocation anyway. My
> document has an instance variable NSMutableArray *actions in which
> these MVActions are stored.
>
> The problem I have is this: when I close my document, it isn't
> deallocated. If the invocations don't retain their arguments, that
> problem is gone, but I do need to retain them. What's a good way to
> solve this? I could release the NSInvocation *action when I put an
> MVAction in the array, but I wonder if there's a better method.
Another fix (re-reading the docs helps) - you can create an
invocation without a target, since you don't want to retain the
target in this case, and the target is known anyway. Then you can use
-invokeWithTarget:myDocument instead of -invoke.
The docs don't tell if -invokeWithTarget: will retain the target, so
call -setTarget:nil after invoking to be sure you don't create a
retain cycle.
Best Regards,
Nir Soffer
DATE : Mon Feb 25 21:49:45 2008
On Feb 21, 2008, at 18:22, Hank Heijink wrote:
> I have a document-based application, and my NSDocument subclass
> runs an experiment which amounts to invoking NSInvocations based on
> certain conditions. These NSInvocations retain their arguments, and
> the target of the NSInvocation is the NSDocument subclass. I need
> to record these invocations as well, so I made a class MVAction as
> follows:
>
> @interface MVAction : NSObject <NSCoding> {
> NSInvocation *action;
> double invocationTime;
> NSString *type;
> NSArray *arguments;
> }
>
> The type is a string representation of the selector used in the
> NSInvocation and the arguments are the arguments of the
> NSInvocation. I did it like this because you can't encode an
> NSInvocation, and I don't need the actual invocation anyway. My
> document has an instance variable NSMutableArray *actions in which
> these MVActions are stored.
>
> The problem I have is this: when I close my document, it isn't
> deallocated. If the invocations don't retain their arguments, that
> problem is gone, but I do need to retain them. What's a good way to
> solve this? I could release the NSInvocation *action when I put an
> MVAction in the array, but I wonder if there's a better method.
Another fix (re-reading the docs helps) - you can create an
invocation without a target, since you don't want to retain the
target in this case, and the target is known anyway. Then you can use
-invokeWithTarget:myDocument instead of -invoke.
The docs don't tell if -invokeWithTarget: will retain the target, so
call -setTarget:nil after invoking to be sure you don't create a
retain cycle.
Best Regards,
Nir Soffer
| Related mails | Author | Date |
|---|---|---|
| Hank Heijink | Feb 21, 17:22 | |
| Nir Soffer | Feb 22, 01:42 | |
| Hank Heijink | Feb 22, 05:00 | |
| Chris Suter | Feb 22, 05:18 | |
| Hank Heijink | Feb 22, 16:36 | |
| Chris Suter | Feb 23, 02:47 | |
| Hank Heijink | Feb 25, 15:49 | |
| Nir Soffer | Feb 25, 21:30 | |
| Hank Heijink | Feb 25, 21:44 | |
| Nir Soffer | Feb 25, 21:49 | |
| Hank Heijink | Feb 25, 22:51 | |
| Chris Suter | Feb 26, 00:03 | |
| Hank Heijink | Feb 27, 16:58 |






Cocoa mail archive

