Update tests with correct memory management