gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libobjc2 objc_setassociatedobject issue


From: Doug Warren
Subject: Re: libobjc2 objc_setassociatedobject issue
Date: Fri, 13 Dec 2013 09:01:18 -0800

Thanks David,

I'll investigate more on our end.  I actually had changed that from NSString to NSObject just to be sure that it wasn't related to that.  (Why in the above stupid example it was cast to NSObject though Alloced as NSString, I had intended it to just be a double dummy NSObject.) The actual case where we ran into this was more complex and I feel there's still an issue but I'll go back and confirm it.  

I was looking at another issue that we had with NSAutoreleasePool and trying to isolate it to a test case.  If I get that I'll construct it as a standalone program as well.  


On Fri, Dec 13, 2013 at 6:44 AM, David Chisnall <address@hidden> wrote:
Ah, sorry, I was reading your example the other way around.  This seems to be because [[NSString alloc] init] returns a singleton on GNUstep.  I don't think this is necessarily a bug, as there's nothing in the contract for NSString that says that it needs to return a new instance for different immutable strings.

In general, using associated objects on immutable objects is a bad idea, because it breaks the assumption that you can use equal instances interchangeably.

David

On 13 Dec 2013, at 14:03, David Chisnall <address@hidden> wrote:

> I've now added a test for this to the libobjc2 test suite, but it passes and so does not appear to be the cause.  Your issue appears to be the dictionary being over-retained.  I will investigate further.
>
> David
>
> P.S. When sending test cases, it helps to send them in the format of a test suite for the thing you are testing, or as stand-alone programs.  I'd have got to this a lot sooner if I didn't have to hack on the test to make it compile.
>
> On 19 Nov 2013, at 01:33, Doug Warren <address@hidden> wrote:
>
>> Hi Guys,
>>
>> Was tracking a memory leak in an existing app and tracked it down to objc_setassociatedobject not working as expected from the code being developed for the Apple Runtime.  The docs around objc_setassociatedobject seem to imply it follows the Apple Runtime but this simple gtest will pass on Apple but fail on libobjc/GNUStep Base:
>>
>> static BOOL deallocCalled = NO;
>> static const char* objc_setAssociatedObjectKey = "objc_setAssociatedObjectKey";
>>
>> @interface NSMutableDictionary(setAssociatedObjectTest)
>> @end
>>
>> @implementation NSMutableDictionary(setAssociatedObjectTest)
>>
>> -(void) dealloc
>> {
>>    deallocCalled = YES;
>>    [super dealloc];
>> }
>>
>> @end
>>
>> TEST(objc_setAssociatedObject, AssociatedObjectsAreReleased)
>> {
>>   address@hidden {
>>        NSObject* object = [[NSString alloc] init];
>>
>>        NSMutableDictionary *info = [NSMutableDictionary dictionaryWithCapacity:1];
>>        objc_setAssociatedObject(object, &objc_setAssociatedObjectKey, info, OBJC_ASSOCIATION_RETAIN);
>>
>>        [object release];
>>    }
>>
>>    ASSERT_TRUE(deallocCalled);
>> }
>>
>> Adding calls to GSDebugAllocationList before/after the autorelease pool:
>> 1    NSDataMalloc
>> 1    GSMutableDictionary
>>
>> Shows that the dictionary leaks.
>>
>> Any thoughts?
>> _______________________________________________
>> Gnustep-dev mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/gnustep-dev
>
>
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/gnustep-dev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]