Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:03:24+00:00 2026-06-10T07:03:24+00:00

I am working in win forms. Getting errors while doing following operation. It shows

  • 0

I am working in win forms. Getting errors while doing following operation.
It shows me System.OutOfMemoryException error when i try to run the operation around 2-3 times continuously. Seems .NET is not able to free the resouces used in operation. The file i am using for operation is quite big, around more than 500 MB.

My sample code is as below. Please help me how to resolve the error.

try
{
   using (FileStream target = new FileStream(strCompressedFileName, FileMode.Create, FileAccess.Write))
   using (GZipStream alg = new GZipStream(target, CompressionMode.Compress))
   {
       byte[] data = File.ReadAllBytes(strFileToBeCompressed);
       alg.Write(data, 0, data.Length);
       alg.Flush();
       data = null;
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:03:25+00:00Added an answer on June 10, 2026 at 7:03 am

    A very rough example could be

    // destFile - FileStream for destinationFile 
    // srcFile - FileStream of sourceFile
    using (GZipStream gz = new GZipStream(destFile, CompressionMode.Compress))
    {
         byte[] src = new byte[1024];
         int count = sourceFile.Read(src, 0, 1024);
         while (count != 0)
         {
             gz.Write(src, 0, count );
             count = sourceFile.Read(src, 0, 1024);
         }
    }
    // flush, close, dispose ..
    

    So basically I changed your ReadAllBytes to read only chunks of 1024 bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following working code in a Win Forms application: Bitmap bitmap =
I'm working on a heavily data-bound Win.Forms application where I've found some strange behavior.
i am working with datagridview in win forms now i have to change the
I was working on how to add glass effect to a win forms in
Working in C# win forms, I'm trying to create a list of items where
I'm currently working on the user interface of a win forms application. The primary
presently i working on win forms(code behind c#) in this i'm using data-grid and
I’ve recently started working on a Win Forms application which needs some improving and
In a C# based Win forms application I am working on a report using
working on this in C# Win Forms. how do set a variable and after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.