diff --git a/loader/include/Geode/utils/addresser.hpp b/loader/include/Geode/utils/addresser.hpp index 2079990c..7f7ae441 100644 --- a/loader/include/Geode/utils/addresser.hpp +++ b/loader/include/Geode/utils/addresser.hpp @@ -29,7 +29,9 @@ namespace geode::addresser { template Class* friendCreate(typename std::void_t(&Class::create))>*) { - return Class::create(); + auto ret = Class::create(); + ret->retain(); + return ret; } template @@ -94,14 +96,10 @@ namespace geode::addresser { return ins; } - template - static void releaseInstance(Class* ins) {} - template - static void releaseInstance(Class* ins) { - // And we delete the new instance because we are good girls - // and we don't leak memories - operator delete(ins); + static Class* cachedInstance() { + static auto ret = generateInstance(); + return ret; } /** @@ -115,7 +113,7 @@ namespace geode::addresser { auto index = indexOf(func); auto thunk = thunkOf(func); - auto ins = generateInstance(); + auto ins = cachedInstance(); // log::debug("[[" + utils::intToHex((void*)ins) + " + " + utils::intToHex(thunk) + "] + // " + utils::intToHex(index) + "]"); @@ -136,7 +134,6 @@ namespace geode::addresser { address = *reinterpret_cast(address); } #endif - releaseInstance(ins); return address; }