Open rafaqz opened 1 year ago
I just ran into this issue, and was looking at how to fix it. It seems like what needs to happen is that a new Geometry/IGeometry should be constructed and returned based on the pointer. The place I'm running into difficulty is that when the old geometry object is GC'ed on the Julia side, it still has a pointer to the GDAL geometry and will free it, leaving the new geometry pointing at unallocated memory. I can think of three solutions:
finalizer(new_function, object)
replaces the finalizer rather than adding a second finalizer, but this behavior doesn't seem to be documented, and I am hesitant to rely on it.destroy
ptr
to a null pointer (or change ptr
to a Union{Ptr, Nothing}
and set to nothing), and check that in destroy
.I kinda like changing ptr
to a Union{Ptr, Nothing}
as it avoids accidental dereferencing of null pointers—not sure how it will affect performance though, or backwards compatibility with any serialized ArchGDAL geometries that may exist.
Since we have a type parameter now, changing the type in GDAL is not enough, we need to update the type and return a new object.