1
/** Implementation for NSGarbageCollector for GNUStep
2
Copyright (C) 2009 Free Software Foundation, Inc.
4
Written by: Richard Frith-Macdonald <rfm@gnu.org>
7
This file is part of the GNUstep Base Library.
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2 of the License, or (at your option) any later version.
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Library General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free
21
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27
#import "Foundation/NSGarbageCollector.h"
29
static NSGarbageCollector *collector = nil;
30
static unsigned disabled = 0;
36
#import "Foundation/NSLock.h"
37
#import "Foundation/NSHashTable.h"
38
static NSLock *lock = nil;
39
static NSHashTable *uncollectable = 0;
42
@implementation NSGarbageCollector
44
+ (id) defaultCollector
52
collector = [self alloc];
57
- (void) collectIfNeeded
60
GC_collect_a_little();
65
- (void) collectExhaustively
84
- (void) disableCollectorForPointer: (void *)ptr
88
if (uncollectable == 0)
90
uncollectable = NSCreateHashTable(NSOwnedPointerHashCallBacks, 0);
92
NSHashInsertIfAbsent(uncollectable, ptr);
112
- (void) enableCollectorForPointer: (void *)ptr
116
if (uncollectable != 0)
118
NSHashRemove(uncollectable, ptr);
127
if (self != collector)
135
- (BOOL) isCollecting
151
return NSDefaultMallocZone();