lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [lmi-commits] master a67848a 1/3: Use 'new(wx)' to allocate me


From: Greg Chicares
Subject: Re: [lmi] [lmi-commits] master a67848a 1/3: Use 'new(wx)' to allocate memory that will be freed by wx
Date: Sun, 7 Feb 2021 23:17:08 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

On 2/6/21 11:00 PM, Vadim Zeitlin wrote:
> On Sat,  6 Feb 2021 14:47:06 -0500 (EST) Greg Chicares 
> <gchicares@sbcglobal.net> wrote:
[...]
> GC> diff --git a/skeleton.cpp b/skeleton.cpp
> GC> index 18e4494..22e96d3 100644
> GC> --- a/skeleton.cpp
> GC> +++ b/skeleton.cpp
> GC> @@ -1081,6 +1081,9 @@ void 
> Skeleton::UponTestFloatingPointEnvironment(wxCommandEvent&)
> GC>  
> GC>  void Skeleton::UponTestPasting(wxCommandEvent&)
> GC>  {
> GC> +    // This uses 'new' rather than 'new(wx)' because the object is
> GC> +    // explicitly deleted by calling Destroy(); yet the Destroy()
> GC> +    // call isn't reached if an exception is thrown.
> GC>      InputSequenceEntry* z = new InputSequenceEntry(frame_, wxID_ANY, 
> "Testing...");
> GC>      LMI_ASSERT(z);
> GC>      wxTextCtrl& t = z->text_ctrl();

[...snip other comments already addressed, though not yet pushed...]

>  Independently of this, we probably ought to use some kind of scope guard
> to ensure that Destroy() is called in any case, as even if there is no real
> memory leak here (because the InputSequenceEntry will eventually be deleted
> by the frame), there is a "window leak", as the entry window will remain
> orphaned on the screen. Or we could just use a unique_ptr as Destroy() for
> a child window is the same as deleting it anyhow.

Writing a scope guard seems like too much work for this test;
unique_ptr sounds much better. But what would become a unique_ptr?
The thing named 'z', of type InputSequenceEntry (derived from wxPanel)?
Would we write
  std::unique_ptr<InputSequenceEntry> z = new(wx) InputSequenceEntry(...);
because there's no make_unique(wx) that would delegate to new(wx)?
And then would we just expunge this line:
      z->Destroy();
? I just feel unsure mixing unique_ptr with wx.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]