Fix memory leak in resource manager + clean