Avoid memory leak when dll is detached