- (call-next-method))))
-
-(defmethod ensure-proxy-instance ((class symbol) location)
- (ensure-proxy-instance (find-class class) location))
-
-(defmethod ensure-proxy-instance ((class proxy-class) location)
- (make-instance class :location location))
+ (let ((instance (apply #'make-proxy-instance class location initargs)))
+ (cache-instance instance)
+ instance))))
+
+(defgeneric make-proxy-instance (class location &key weak)
+ (:documentation "Creates a new proxy object representing the foreign
+object at the give location. If WEAK is non NIL the foreign memory
+will not be released when the proxy is garbage collected."))
+
+(defmethod make-proxy-instance ((class symbol) location &key weak)
+ (ensure-proxy-instance (find-class class) location :weak weak))
+
+(defmethod make-proxy-instance ((class proxy-class) location &key weak)
+ (declare (ignore weak-p))
+ (let ((instance (allocate-instance class)))
+ (setf (slot-value instance 'location) location)
+ (unless weak
+ (finalize instance (instance-finalizer instance)))
+ instance))