garbage collection - How to hint C# runtime that myclass is using X amount of unmanaged memory -


to let call myclass destructor or idisposable release method?

class myclass:idisposable {      [dllimport(..)]      public static extern intptr allocate(...);       public myclass()      {           allocate();      }       ~myclass()      {          dispose();      } } 

where client developer doesn't care (or doesn't remember) using myclass as

    using(myclass foo = new myclass())     {       } 

but uses like

   myclass bar = new myclass(); 

without memory control designs in method. need guaranteed way(or @ least hint) of telling garbage collector may call destructor of myclass or call dispose method after scope exited(or when memory gets fragmented enough) of hint.

is there kind of hint applicable these

  • attribute:

just adding struct layout bu different

[memoryattribute.uses10mbunmanaged] class myclass {} 
  • garbage collector:

i don't know how relate garbage collection class instances

gc.addmemorypressure(10*1024*1024) in myclass constructor  // not per instance related.  // gc still doesn't know class making percentage of // pressure(or it?) 
  • marshal.allochglobal instead of allocate() "c" space

then, when developer creates hundreds of myclass instances , when memory gets full, runtime starts disposing out-of-scope instances accordingly unmanaged(marshal.allochglobal)+managed(new float[1000]) memory usages instead of managed usage.


maybe garbage collector learns in run-time when collects/finalizes amount of instances(and watches total ram consumed) , picks necessary ordering between objects have unmanaged memory allocations?


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -