[Mono-devel-list] Limiting Memory Allocation

Ben Maurer bmaurer at ximian.com
Wed May 4 11:44:18 EDT 2005


On Wed, 2005-05-04 at 16:25 +0100, Jim Purbrick wrote:
> --- Jim Purbrick <jimpurbrick at yahoo.co.uk> wrote:
> > I've got the allocation tracking working with the
> > profiling API, can work out how much memory a script
> > has allocated and throw an exception from there when
> > the limit is reached (admitedly after the allocation
> > which breaks the limit). Is there a way to track how
> > much of a scripts memory is freed so I can work out
> > the current allocated total for each script? I
> > imagine this might be complicated by the GC.
> 
> It struck me that one way to trap memory freed by the
> GC would be to make a call from the finalizer of
> System.Object, which works fine.

That would kill performance. 

> The problem is, when I add a field to System.Object to
> store the Id of the allocated script, mcs crashes
> seemingly because I'm adding a field to a class with
> no base.

The runtime has builtin assumptions about the sizeof (Object). Its not a
bug, because we don't allow you to add fields to an object we know about
in the runtime.

> Alternatively if anyone can see a less crazy way to
> make this work, I'd love to hear about that too!

Look at heap-prof. My profiler traps memory freed by the gc.

-- Ben




More information about the Mono-devel-list mailing list