unsafe operations

A

Andre

if I have an unsafe method that takes in two arrays, performs some
operations and returns; I know that the garbage collector will not
collect objects allocated inside the unsafe method. However, if I'm
calling this method from a main() method of a class which is safe (i.e
managed), will the allocated array (which, suppose, has been allocated
inside the main() method) be collected by the garbage collector after
it's been used? Also, how do we delete heap allocated objects (suppose a
temporary array) from within the unsafe method? Is the unsafe method
treated as a region (term taken from strict Realitime environment) and
discarded by the GC once it's been used (or is it the method stack
that's discarded)? Just making sure I know what my code does before I
implement it :) thanks

-Andre
 
R

Rob Teixeira [MVP]

The GC will collect objects in an unsafe block. The trick is to pin the
objects so the GC *doesn't* collect them while you're using them. That's
what the "fixed" block is for. Look up the Fixed block in the help file, and
there's a sample. Once the code gets passed the fixed block, the objects
become unpinned, and the GC is able to collect them on the next round.

-Rob [MVP]
 
R

Rob Teixeira [MVP]

I'd have to re-read the specs on the current GC, but the bottom line is that
at some point, everything gets collected.
There is no explicit delete of managed memory.

-Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top