Contents (package MULK.OBJECTIVE-CL)


Standard Generic Function FOREIGN-VALUE-LISP-MANAGED-P

Purpose:

Determine or change whether a foreign value will be garbage-collected.

Syntax:

foreign-value-lisp-managed-p foreign-value

(setf foreign-value-lisp-managed-p) managed-p foreign-value

Arguments and Values:

foreign-value --- an object.

managed-p --- a generalized boolean.

foreign-value-lisp-managed-p returns: a boolean.

Description:

When a value of a struct or union type is returned by a method call or given as an argument to a method implemented in Lisp, it is encapsulated in a foreign-value that by default deallocates the value upon its finalisation by the garbage collector.

foreign-value-lisp-managed-p determines whether this automatic deallocation is enabled. Setting foreign-value-lisp-managed-p to false inhibits automatic deallocation of foreign-value.

Rationale:

Having to manually deallocate all structs returned by values or passed as arguments to methods implemented in Lisp would require knowledge of whether a pointer or an actual struct was returned or passed, respectively. It would also prevent the user from simply discarding struct return values as any Lisp or Objective-C programmer could normally do without harm.

On the other hand, automatic deallocation means that anytime the user wanted to save the struct in a foreign slot as a pointer, they would need to copy the struct first, which may be expensive and is certainly inconvenient.

Doing the right thing therefore inevitably implies some kind of user action some of the time. Requiring the user to mark non-GCable objects seems like an acceptable trade-off.

See also:

foreign-value