Project

General

Profile

Bug #3807

[wt-git] WItemDelegate causes memory leak?

Added by Anonymous over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Benoit Daccache
Target version:
Start date:
02/19/2015
Due date:
% Done:

0%

Estimated time:

Description

Hi,

I specialised the WItemDelegate class and I saw that the editor widget is never destructed. The default implementation of doCloseEditor is:

void WItemDelegate::doCloseEditor(WWidget *editor, bool save) const
{
  closeEditor().emit(editor, save);
}

When the editor has to be destructed? I suppose after emitting the closeEditor signal, i.e., :

void WItemDelegate::doCloseEditor(WWidget *editor, bool save) const
{
  closeEditor().emit(editor, save);
  delete editor;
}

Best regards,

Stoycho


Files

Main.cpp (3.27 KB) Main.cpp memory leak when delegate is set for column > 0 Стойчо Стефанов Stoycho Stefanov, 03/24/2015 05:41 PM
#1

Updated by Koen Deforche over 7 years ago

  • Status changed from New to Rejected
  • Assignee set to Koen Deforche

Hey,

The 'editor' widget is in fact simply the widget rendered by the item delegate for a particular cell: it's treated in the same way as a normal view widget, and thus the tableview or treeview will delete it.

Regards,

koen

#2

Updated by Стойчо Стефанов Stoycho Stefanov over 7 years ago

Hey Koen,

let us consider the following scenario, where you're editing the same cell for example 10 times consecutively. Than you have created 10 editor widgets for the same cell, because every time you're editing createEditor is called and a new editor widget is instantiated. I think it's wrong to create every time a new editor when editing, not reuse it and destroy them with the parent view widget. With other words, after doCloseEditor is called the editor widget still exists despite it's never accessed again and still be there until the view widget is destructed. I thing it's much better to delete the editor before exiting doCloseEditor, OR reuse it and create it only once by the first call of createEditor.

Regards,

Stoycho

#3

Updated by Koen Deforche over 7 years ago

  • Status changed from Rejected to Feedback

In the scenario you describe, each time you code the editor it will be destroyed because the editor is later replaced by a view. So in no situation will there exist more than one widget for a particular cell at the same time. The fact that we do not reuse a previous editor has to do with flexibility, as that would impose that a single cell should always have the same editor widget.

#4

Updated by Стойчо Стефанов Stoycho Stefanov over 7 years ago

Ok, perhaps I have a bug in my delegate specialisation. But If I do not delete the editor explicitly in doCloseEditor, editor widgets are never destroyed, neither by replacing with a view nor by the tree view destructor. I'll let you know whether I can reproduce it in a test case application. Unfortunately, I do not have currently time for this.

Regards,

Stoycho

#5

Updated by Koen Deforche over 7 years ago

Yes, I would be interested in such a test case as we cannot reproduce this with the standard item delegate or a custom one (like ComboBoxDelegate)

#6

Updated by Стойчо Стефанов Stoycho Stefanov over 7 years ago

Hey,

I got it. Here is the test case for wt-git revision 1084.

The editor widget is destroyed when editing within column 0, bit not within column 1, of a tree view.

regards,

Stoycho

#7

Updated by Koen Deforche over 7 years ago

  • Status changed from Feedback to InProgress
  • Assignee changed from Koen Deforche to Benoit Daccache
  • Target version set to 3.3.4
#8

Updated by Benoit Daccache over 7 years ago

  • Status changed from InProgress to Resolved
#9

Updated by Koen Deforche over 7 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF