如何解决Tkinter GUI中意外的数据泄漏
最近,我开始用Python制作一个名为Robbery Clicker的游戏。我的项目使用tkinter
,并且相对性最近很好。
本质上,下面显示的代码将在GUI上的按钮小部件调用后运行:
def auto1():
global coins
global item1_auto
if coins >= 250:
coins -= 250
runauto1()
item1_auto = 1
click1["state"] = DISABLED
click1.update()
click1_auto.config(state=DISABLED)
def runauto1():
global coins
global item1_sleep
global item1
global item1_cost
click1.after(int(item1_sleep * 1000),runauto1)
click1.after(int(item1_sleep * 1000),do1())
但是,在执行此代码后,单击该按钮后立即发生内存泄漏,并且在解决该问题大约10秒钟后,将导致无法解决的内存泄漏。
我的整个代码可以在这里找到:https://pastebin.com/pHwZFwZV
解决方法
至少部分问题是这样的: public function create()
{
// checking if authenticated but need to check if email verified also
if (Auth::check()) {
// Get the currently authenticated user...
$user = Auth::user();
// get the list of states
$states = State::orderBy('name','asc')->get();
// get all cities by state_id
$state_id = '1';
$cities = City::where('state_id',$state_id)->orderBy('name','asc')->get();
return view('pages.create_product',['user' => $user,'states' => $states,'cities' => $cities]);
} else {
return redirect()->route('login');
}
}
您正在立即呼叫click1.after(int(item1_sleep * 1000),do1())
,而不是将其放入队列。就像您执行do1()
一样。如果这导致调用result=do1(); click1.after(int(item1_sleep * 1000),None)
,您将快速创建递归错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。