This commit fixes the potential memory leak in the ObjectFactory class and adds new tests for the memory leaks.