diff --git a/src/core/subscribemanager.cpp b/src/core/subscribemanager.cpp
index 9d04039..29f5e5b 100644
--- a/src/core/subscribemanager.cpp
+++ b/src/core/subscribemanager.cpp
@@ -22,6 +22,7 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
#include "module/http/request.h"
#include "module/http/response.h"
#include "net/http_subscribe.h"
+#include "module/request_temp_ptr.h"
fastweb::subscribe_manager::subscribe_manager(fastweb::app* app) :Interface(app)
{
}
@@ -62,6 +63,9 @@ bool fastweb::subscribe_manager::callback(network::http::request* request, netwo
bool ok_continue = false;
auto lua = app()->state->get();
std::string exception_string;
+
+ // 临时指针管理(待释放资源)
+ module::request_temp_ptr request_temp_ptr;
try
{
sol::load_result script = lua->state->load_file(app()->config->website.dir + filepath);
@@ -85,7 +89,10 @@ bool fastweb::subscribe_manager::callback(network::http::request* request, netwo
exception_string = e.what();
if (app()->config->website.debug)
LOG_ERROR("[subscribe][" + request->filepath() + "]: " + e.what());
- }
+ }
+ // 释放临时指针
+ request_temp_ptr.clear();
+ // 释放lua资源
lua->state->collect_garbage();
app()->state->push(lua);
diff --git a/src/module/basemodule.h b/src/module/basemodule.h
index 942bea0..5fc7a02 100644
--- a/src/module/basemodule.h
+++ b/src/module/basemodule.h
@@ -22,8 +22,13 @@ namespace module
///
/// 全局变量阶段获取自身指针
///
- ///
+ ///
virtual void* self() { return this; }
+
+ ///
+ /// 释放自身(非指针释放,非lua引用释放,仅释放内部资源)
+ ///
+ virtual void self_free() = 0;
};
}
diff --git a/src/module/mutex.h b/src/module/mutex.h
index 7f4103a..726cd14 100644
--- a/src/module/mutex.h
+++ b/src/module/mutex.h
@@ -29,6 +29,7 @@ namespace module
// 通过 imodule 继承
virtual void regist_global(const char* name, sol::state* lua);
virtual void delete_global() { delete this; }
+ virtual void self_free() { }
std::mutex m_mutex;
};
diff --git a/src/module/queue.h b/src/module/queue.h
index 7f17e34..6a62097 100644
--- a/src/module/queue.h
+++ b/src/module/queue.h
@@ -15,6 +15,7 @@ namespace module
static void regist(sol::state* lua);
virtual void regist_global(const char* name, sol::state* lua) override;
virtual void delete_global() { delete this; }
+ virtual void self_free() {}
private:
ylib::queue m_queue;
};
diff --git a/src/module/request_temp_ptr.cpp b/src/module/request_temp_ptr.cpp
new file mode 100644
index 0000000..6e5b90a
--- /dev/null
+++ b/src/module/request_temp_ptr.cpp
@@ -0,0 +1,47 @@
+/*Software License
+
+Copyright(C) 2024[liuyingjie]
+License Terms
+Usage Rights
+
+Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
+If the source code is modified, the modifications must be open - sourced under the same license.This means that the modifications must be disclosed and accompanied by a copy of this license.
+Future Versions Updates
+From this version onwards, all future releases will be governed by the terms of the latest version of the license.This license will automatically be nullified and replaced by the new version.
+Users must comply with the terms of the new license issued in future releases.
+Liability and Disclaimer
+This software is provided “as is”, without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non - infringement.In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
+Contact Information
+If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
+*/
+#include "request_temp_ptr.h"
+
+module::request_temp_ptr::request_temp_ptr()
+{
+}
+
+module::request_temp_ptr::~request_temp_ptr()
+{
+}
+
+void module::request_temp_ptr::push(void* value)
+{
+ m_queue.push(value);
+}
+void module::request_temp_ptr::clear()
+{
+ while (m_queue.size() > 0)
+ {
+ auto base = (module::base*)m_queue.front();
+ m_queue.pop();
+ base->self_free();
+ }
+}
+void module::request_temp_ptr::regist(sol::state* lua)
+{
+ lua->new_usertype("fw_request_temp_ptr",
+ "new", sol::constructors(),
+ "push", &module::request_temp_ptr::push,
+ "clear", &module::request_temp_ptr::clear
+ );
+}
\ No newline at end of file
diff --git a/src/module/request_temp_ptr.h b/src/module/request_temp_ptr.h
new file mode 100644
index 0000000..de40485
--- /dev/null
+++ b/src/module/request_temp_ptr.h
@@ -0,0 +1,22 @@
+#pragma once
+#include "sol/sol.hpp"
+#include "module/basemodule.h"
+#include
+namespace module
+{
+ class request_temp_ptr{
+ public:
+ request_temp_ptr();
+ ~request_temp_ptr();
+
+
+ void push(void* value);
+ void clear();
+
+ static void regist(sol::state* lua);
+ private:
+ std::queue m_queue;
+ };
+
+}
+
diff --git a/src/module/timer.h b/src/module/timer.h
index a8f3dd0..332d206 100644
--- a/src/module/timer.h
+++ b/src/module/timer.h
@@ -39,6 +39,7 @@ namespace module
static void regist(sol::state* lua);
virtual void regist_global(const char* name, sol::state* lua) override;
virtual void delete_global() { delete this; }
+ virtual void self_free() { }
private:
virtual bool run();