[Mono-list] Fwd: Threading and IO problem

Yanko Hernández Álvarez yhdezalvarez at gmail.com
Mon Mar 10 10:08:48 EDT 2008


> >  OTOH and as a curiosity: Is there any way to free memory directly (at
> >  CIL level I mean) without using the GC? for instance:
> >
> >
> >    while ((Str = SR.ReadLine()) != null) ;
> >
> >  with a little flow analisis we can determine Str isn't used after it
> >  is assigned. is there a way to deallocate it efficiently without
> >  waiting for the GC to collect memory?
>
>  This would also have to be determined for the ReadLine() method
>  (making sure it doesn't stash a reference somewhere) as well as any
>  methods that ReadLine() passes that string reference to (which may be
>  none, but you get my point).

Yes, I know. When I asked about it I was thinking of a way for the JIT
to rely on the compiler to do this analysis, and don't waste JIT
compilation time on this matter. I mean, to successfully  implement
this, there must be a way to tell the runtime this object won't be
used in the future without it having to wait for the GC to extract
this knowledge from the live object references.

This would allow to:
* convey more information of the object usage to the runtime. The
runtime could use this information to detect incorrect programmer
assumptions ("This object is of no use at this point, so the GC will
collect it..") about the program behavior (for instance in debug mode,
this could be treated as a hint). See for example bug
#357649(https://bugzilla.novell.com/show_bug.cgi?id=357649). I assume
(from comment #3) the library programmer thought no one was using the
input stream at his point (when a "Process" object is finalized), so
let's close it. There is no way to assert this information ("there is
no reference to this stream") to the runtime (at least I don't know
how to do it). Result: this particular error. This would also help to
detect unexpected "... stashed references somewhere" (memory leaks in
many cases ;-) which is a good thing I suppose.
* lessen the pressure on the GC (using some invocation switch to the
runtime) to treat these hints as deallocations.
* anything in between.

If the runtime doesn't help with this, this would only be possible at
JIT time (or at AOT compilation with a little extra support from the
mono runtime).

Well to much daydreaming for today, back to work

Best regards
      Yanko


More information about the Mono-list mailing list