c# - How Marshal.FreeHGlobal can free unmanned array? -


i have reserved unmanned array using:

intptr ptr = marshal.allochglobal(marshal.sizeof(array[0]) * array.length); 

then free using:

marshal.freehglobal(ptr ); 

as far read, free memory correctly , no memory leak gonna happen. question: true? if is, how works? marshal state-full , store meta-data every reserved data?

the allochglobal method exposes localalloc function. , freehglobal method exposes localfree function. memory management not being done managed component. done code behind these windows api functions.

to answer question: yes has keep track of allocated size. can retrieve size of handle calling localsize function. honest, don't know how being done internally, don't need know that.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -