@@ -16,11 +16,23 @@ @implementation OFList - init { if ((self = [super init])) { first = NULL; - last = NULL; + last = NULL; + retain_and_release = YES; + } + + return self; +} + +- initWithRetainAndReleaseEnabled: (BOOL)enabled +{ + if ((self = [super init])) { + first = NULL; + last = NULL; + retain_and_release = enabled; } return self; } @@ -57,11 +69,13 @@ last = o; if (first == NULL) first = o; - [obj retain]; + if (retain_and_release) + [obj retain]; + return o; } - (of_list_object_t*)prepend: (id)obj { @@ -76,11 +90,13 @@ first = o; if (last == NULL) last = o; - [obj retain]; + if (retain_and_release) + [obj retain]; + return o; } - (of_list_object_t*)insert: (id)obj before: (of_list_object_t*)listobj @@ -97,11 +113,13 @@ listobj->prev = o; if (listobj == first) first = o; - [obj retain]; + if (retain_and_release) + [obj retain]; + return o; } - (of_list_object_t*)insert: (id)obj after: (of_list_object_t*)listobj @@ -118,11 +136,13 @@ listobj->next = o; if (listobj == last) last = o; - [obj retain]; + if (retain_and_release) + [obj retain]; + return o; } - remove: (of_list_object_t*)listobj { @@ -134,9 +154,13 @@ if (first == listobj) first = listobj->next; if (last == listobj) last = listobj->prev; + if (retain_and_release) + [listobj->object release]; + [self freeMem: listobj]; + return self; } @end