javax.naming.spi.*ObjectFactory.getObjectInstance() method uses the obj parameter to construct the Object to be returned.
The obj parameter must be cleared after it's use is over, i.e of creating an Object to be returned. Otherwise, it leads to resource leak.
This must be documented either in the Javadoc or in the tutorial.
A customer from Corio Inc was not closing the obj passed in as a DirContext instance in his ObjectFactory. That lead to socket leak because the connections from the DirContext to the LDAP server weren't released at all. He had opted for connection pooling and none of the connections could be reused as they were all in a busy state forever.