I have this code in a slot function.
QCursor cur=this->cursor();
QMenu* pRightKeyMenu=new QMenu(this);
pRightKeyMenu->popup(cur.pos());
When I click the right mouse key, it will be invoked. After that, I find that memory is going up up up… and never goes down. How can I fix that?
The variable
pRightKeyMenuis leaking because you’re not releasing it.One possible solution is to reuse it, since, by your code, the created QMenu is always the same: