-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Associated objects bugs #330
Comments
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
static void *AssociatedObjectKey = &AssociatedObjectKey;
void testAssociatedObjectMemoryLeak() {
__weak id weakObject;
@autoreleasepool {
NSObject *testObj = [NSObject new];
NSString *associatedValue = [NSString stringWithFormat:@"TestValue %p", AssociatedObjectKey]; // Force an allocated string
objc_setAssociatedObject(testObj, AssociatedObjectKey, associatedValue, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
weakObject = associatedValue;
assert(weakObject != nil && "Associated object should be retained inside autoreleasepool");
}
// After the autoreleasepool block, testObj should be deallocated, and so should the associated object.
assert(weakObject == nil && "Associated object should be released after the owner is deallocated");
}
int main() {
testAssociatedObjectMemoryLeak();
printf("Test passed: No memory leak detected.\n");
return 0;
} This passes on both macOS and Ubuntu 24.10 with libobjc2 master. It would be great to have a minimal test case to reproduce this. |
Ah nvm |
All tests in |
I think there are two bugs in the associated objects implementation as follows:
These issues are demonstrated in the gnustep-base tests (marked as hopeful) in Tests/base/Functions/runtime.m
These tests pass on OSX
The text was updated successfully, but these errors were encountered: