Is this when the first observer is added to each of the 100k objects?

Yes, it happens for the first observer I add.

But I expressed the problem not good enough. Adding an observer is realized by adding an associated reference (with objc_addAssociatedObject(), new in Snow Leopard) to the observed object. So the main problem is that adding a single associative reference to an object results in an allocation of 2048 byte block. If I do this to my 100.000 objects, about 200MB are allocated (in comparison to about 3MB for the objects). These blocks seem to be scanned memory, as I also noticed significant delays as the garbage collector scanned and collected.

This amount of memory seems to be allocated on purpose (see the ::reserve method on top of the stack trace shown below) but seems way too high for the general case of adding a single associative reference!

0 libauto.dylib std::vector<__gnu_cxx::_Hashtable_node<std::pair<void* const, void*> >*, Auto::AuxAllocator<__gnu_cxx::_Hashtable_node<std::pair<void* const, void*> >*> >::reserve(unsigned long)
   1 libauto.dylib Auto::Zone::set_associative_ref(void*, void*, void*)
   2 AssociativeReferences -[Object setName:]
   3 AssociativeReferences main
   4 AssociativeReferences start

The Object class is implemented as follows:

static char name_key;

@implementation Object

- (NSString*)name {
        return objc_getAssociatedObject(self, &name_key);
}

- (void)setName:(NSString*)aName {
objc_setAssociatedObject(self, &name_key, aName, OBJC_ASSOCIATION_COPY);
}

@end

Torsten







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to