[Interest] QList operator[]

Thiago Macieira thiago.macieira at intel.com
Sat Jan 10 22:55:09 CET 2015


On Saturday 10 January 2015 16:30:08 K. Frank wrote:
> Hi Thiago!
> 
> On Sat, Jan 10, 2015 at 1:56 PM, Thiago Macieira
> 
> <thiago.macieira at intel.com> wrote:
> > On Saturday 10 January 2015 12:19:26 K. Frank wrote:
> >> > Seems odd behaviour to
> >> > get from a couple of lines of code like that.  Would never have
> >> > expected
> >> > that to be a memory leak!
> >> 
> >> I agree that something odd is going on here.  I understand why you
> >> got a deep copy that you didn't anticipate, but I don't see why that
> >> would lead to a memory leak.
> >> 
> >> I'm hoping that the experts can shed some more light on this issue.
> > 
> > There is no leak.
> 
> Would you care to elaborate?
> 
> According to Brad:
> 
>    I added a couple lines of code to an app and suddenly it started
>    chewing through memory at an unbelievable rate.  I watched it
>    get up to 12 GB at which point it hit my virtual memory limit ...
> 
> One of the added lines was:
> 
>    const CultureItem& it = culture.items[i]; // added this
> 
> This is a variable local in scope to a for-loop.  It seems unlikely
> that a *single* deep copy of culture.items[i] would eat up 12+ GB,
> and -- barring my misunderstanding of some C++ issue -- since
> "it" goes out of scope at the end of the loop, only one deep copy
> should exist at a time.
> 
> The symptoms Brad describes sure sound like a leak, so I would
> like to understand your analysis of the situation.

It sounds like a leak but isn't.

You're probably experiencing memory fragmentation or something else.

Try using a memory debugger like Valgrind's memcheck or massif.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list