I have seen consistent GEOSContextHandle leak when a thread using GEOS exits. The source code is in django/contrib/gis/geos.
I can get rid of the leak by clearing all attributes of io.thread_context before exiting that thread.
It seems to me that the root cause is the destructors of thread local objects in io.thread_context call GEOS functions, so they need the GEOSContextHandle. If threadsafe.thread_context has been cleared by Python engine, they will create another one.
Assume Python clears threading.local objects in this order:
1. thread_safe.thread_context
2. io.thread_context
When doing the second step above, it creates another GEOScontextHandle and saves to thread_safe.thread_context.handle. And this is never cleared again.
This is just my thought. Should a Django ticket be created for this?
Best regards,
Yong Li