Use weak ptr for error callback so classes are correclty freed