[vlc-devel] commit: macosx: fix VLC object leaks (Derk-Jan Hartman )

Derk-Jan Hartman hartman at videolan.org
Fri Apr 3 13:25:07 CEST 2009


On 3 apr 2009, at 13:19, Pierre d'Herbemont wrote:
> As would Remi says, this looks highly suspicious ;-)

That's because it's autorelease. It looks bad, but if you think  
properly about it, it's just perfect.

You hand something with retaincount 0 to the NSMenuItem. That will  
retain it. When another object becomes the represented object,  
retainCount becomes 0 and at the end of all the GUI updates, the  
"something" is dealloc.


> See my last email. I think we can just forget about the NSValue here.
> (And appropriately fix users of representedValue).

You are right I think. (though autorelease will still be needed).

DJ

>
> On Fri, Apr 3, 2009 at 1:11 PM, git version control  
> <git at videolan.org> wrote:
>> vlc | branch: master | Derk-Jan Hartman <hartman at videolan.org> |  
>> Fri Apr  3 13:06:30 2009 +0200|  
>> [8bfec18d590fc1b109016c030402856285918294] | committer: Derk-Jan  
>> Hartman
>>
>> macosx: fix VLC object leaks
>>
>> When building the menu's, autorelease the VLCAutoGeneratedMenu's  
>> instead of retaining. The NSMenuItem will do a retain/release for  
>> the live of the object in the NSMenuItem and thus once the menu's  
>> are done using the object, their retaincount will be 0 and they  
>> will be dealloc'ed at the end of the EventLoop. (An eventloop is  
>> One run of GUI updates you might say).
>>
>>> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8bfec18d590fc1b109016c030402856285918294
>> ---
>>
>>  modules/gui/macosx/controls.m |   10 +++++-----
>>  1 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/modules/gui/macosx/controls.m b/modules/gui/macosx/ 
>> controls.m
>> index c6b9f67..bf953c0 100644
>> --- a/modules/gui/macosx/controls.m
>> +++ b/modules/gui/macosx/controls.m
>> @@ -710,13 +710,13 @@
>>     case VLC_VAR_VOID:
>>         o_data = [[VLCAutoGeneratedMenuContent alloc]  
>> initWithVariableName: psz_variable ofObject: p_object
>>                 andValue: val ofType: i_type];
>> -        [o_mi setRepresentedObject: [NSValue valueWithPointer: 
>> [o_data retain]]];
>> +        [o_mi setRepresentedObject: [NSValue valueWithPointer: 
>> [o_data autorelease]]];
>>         break;
>>
>>     case VLC_VAR_BOOL:
>>         o_data = [[VLCAutoGeneratedMenuContent alloc]  
>> initWithVariableName: psz_variable ofObject: p_object
>>                 andValue: val ofType: i_type];
>> -        [o_mi setRepresentedObject: [NSValue valueWithPointer: 
>> [o_data retain]]];
>> +        [o_mi setRepresentedObject: [NSValue valueWithPointer: 
>> [o_data autorelease]]];
>>         if( !( i_type & VLC_VAR_ISCOMMAND ) )
>>             [o_mi setState: val.b_bool ? TRUE : FALSE ];
>>         break;
>> @@ -821,7 +821,7 @@
>>             o_lmi = [o_menu addItemWithTitle: o_title action:  
>> pf_callback keyEquivalent: @""];
>>             o_data = [[VLCAutoGeneratedMenuContent alloc]  
>> initWithVariableName: strdup(psz_variable) ofObject: p_object
>>                     andValue: another_val ofType: i_type];
>> -            [o_lmi setRepresentedObject: [NSValue valueWithPointer: 
>> [o_data retain]]];
>> +            [o_lmi setRepresentedObject: [NSValue valueWithPointer: 
>> [o_data autorelease]]];
>>             [o_lmi setTarget: self];
>>
>>             if( !strcmp( val.psz_string, val_list.p_list- 
>> >p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
>> @@ -836,10 +836,10 @@
>>                                  [NSString stringWithFormat: @"%d",
>>                                  val_list.p_list->p_values[i].i_int];
>>
>> -            o_lmi = [[o_menu addItemWithTitle: o_title action:  
>> pf_callback keyEquivalent: @""] retain ];
>> +            o_lmi = [o_menu addItemWithTitle: o_title action:  
>> pf_callback keyEquivalent: @""];
>>             o_data = [[VLCAutoGeneratedMenuContent alloc]  
>> initWithVariableName: strdup(psz_variable) ofObject: p_object
>>                     andValue: val_list.p_list->p_values[i] ofType:  
>> i_type];
>> -            [o_lmi setRepresentedObject: [NSValue valueWithPointer: 
>> [ o_data retain]]];
>> +            [o_lmi setRepresentedObject: [NSValue valueWithPointer: 
>> [ o_data autorelease]]];
>>             [o_lmi setTarget: self];
>>
>>             if( val_list.p_list->p_values[i].i_int == val.i_int && ! 
>> ( i_type & VLC_VAR_ISCOMMAND ) )
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> http://mailman.videolan.org/listinfo/vlc-devel
>>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> http://mailman.videolan.org/listinfo/vlc-devel
>




More information about the vlc-devel mailing list