[Issue 5326] GC -- 99% CPU in gc at gcx@Gcx at mark()

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 10 23:18:10 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5326



--- Comment #4 from nfxjfg at gmail.com 2010-12-10 23:16:27 PST ---
(In reply to comment #3)
> > PS: scope doesn't work on arrays. Your example code never explicitly free's the
> memory.
> 
> That explains everything... but then, how do we delete arrays?

You can free heap allocated arrays by "delete somearray;" (deprecated in D2).

I'm not sure what's the proper way of deleting an array is. As you can see in
the implementation for "delete <array>;", it's not that trivial:
http://www.dsource.org/projects/druntime/browser/trunk/src/rt/lifetime.d#L937
PS: That code may contain a bug. It may pass a pointer to gc_free() that is not
the start of a memory block, but gc_free() could have trouble with that and
have undefined effects on the GC heap integrity, but I digress.

When you allocate a class using scope on classes, it is normally allocated on
the stack. Doing this with arrays is hard; you need to use alloca() and turn
the resulting void* into an array...

Also, the idea with void[] was probably that it could contain *anything* that
can exist in memory. Thus the GC has to assume that it may contain pointers.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list