Clear big AAs

useo useo6 at start.bg
Wed Jun 1 08:51:40 PDT 2011


== Auszug aus David Nadlinger (see at klickverbot.at)'s Artikel
> I realize that this might sound strange, but try setting myAA to
null
> after clear(), this should fix the crash.
> David
> On 5/31/11 4:00 PM, useo wrote:
> > Hi,
> >
> > I'm trying to clear big associative arrays, but I always get an
> > object error - what I currently doing is:
> >
> > private string[uint] myAA;
> >
> > void main() {
> >
> >     fill(myAA);
> >     myAA.clear();
> >     fill(myAA); // object.Error: Access Violation
> > }
> >
> > void fill(string[uint] aa) {
> >     for (uint i = 0; i<  10_000_000_000; i++) {
> >        myAA[i] = std.conv.to!(string)(i);
> >     }
> > }
> >
> > I already saw the bug report at http://www.digitalmars.com/d/
archives/
> > digitalmars/D/bugs/
> >
Issue_5683_New_Calling_.clear_on_a_fresh_associative_array_causes_subsequent_segfault_28632.html
> > and I'm also using 2.052 - as I saw at the change-log of 2.053
it's
> > also unfixed. So... is there any solution to clear associative
arrays
> > without memory leaking?

Thanks a lot,

I solved it by using

pGraphics.clear();
pGraphics = null;
// pGraphics.rehash();

I thought this'll solve my problem, but it doesn't... I've to fill my
AA every 500 ms with around 250 values (in principle much less than
10_000_000_000). When I start my application (in this context, my
game), it works as needed (around 2000 fps/s) but after some seconds,
the fps-rate drops down to 1/s and back to normal (and again, and
again...). When I remove the command to clear the array, it works
without dropping down to 1 fps. I this case I can't update my screen
as needed. I also tried to delete the class instance which contains
the array and create an new but it's the same as before (it drops
down to 1 fps). Is there anything I forgot to consider?


More information about the Digitalmars-d-learn mailing list