4
Reply

How to release managed memory in C#

Jorge L Fernandez

Jorge L Fernandez

16y
10.2k
0
Reply

    garbage collect

    I got into the AppDomain benefits an implemented another solution to the initial problem; - Create an AppDomain. - Executing the Assembly into the created domain. - Unload the domain. Both solutions are equivalent in terms of performance and memory. Anyways, if some other approach are possible I will appreciate your comments.

    I realized that my problem was that many Bitmap object were created through the process. I invoked the GC.Collect method but this was causing a performance impact. Then I start looking for a solution to release by my self those Bitmap. Bitmap are created in the managed heap which is not intended to be accessed directly by the user (coder), so, the solution I found was not elegant but solved my problem with no performance impact. I created a separated program that creates the Bitmaps and is called by the main program by using the Process class. When this separated program starts it does its work and then when is closed its occupied memory is released avoiding the OutOfMemoryException. If you have any suggestion or any other solution I will appreciate your response.

    Hi, I'm creating a big amount of images at runtime (thousands) and I'm getting and OutOfMemory Exception. I have detected in my code where the problem is and it's an array of bytes that is being created many times and allocating memory until the GC do its work. How do I explicitly can free that byte array in order to avoid calling GC.Collect method? Thanks in advanced