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

  • Home
  • SEARCH
  • 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 4024990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:47:27+00:00 2026-05-20T10:47:27+00:00

In my application I need to load large files (can be about ~ 250

  • 0

In my application I need to load large files (can be about ~ 250 MB) into memory, I’m doing it in a lazy way – when user ask to see a file – I’m loading it. After that, every time user tries to access the file, I’m able to show it immediately , because it’s already located in memory.
So, The problem is with garbage collection…
Every file I’m loading, I’m loading through a WeakReference,
BUT :
I tested It a few times, I was able to load about 3GB into memory (than app become not usable), but GC did not occurred. I’m not able to call GC.Collect(2), because I can not determine time to call it, so how to tell GC to collect memory (weakreferences) in good moments (damn, 3GB is too much…It seems GC just does not doing his job)
Hot to resolve it? I really need lazy loading, but I need memory to be collected when process uses more than 1GB of it, or something like that

  • 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-05-20T10:47:28+00:00Added an answer on May 20, 2026 at 10:47 am

    There is a static function called GC.GetTotalMemory(bool forceFullCollection) ( http://msdn.microsoft.com/en-us/library/system.gc.gettotalmemory.aspx ). You can use it to force a Garbage Collection before loading a new file into the memory, if you have passed some threshold.

    Edit: a possible implementation

    public MyFile GetMyFile(){
       if ( !is_my_file_in_memory() ) {
          if (CG.GetTotalMemory(false) > MY_THRESHOLD ) {
    
            GC.Collect(2);
    
          }
          load_my_file_in_memory();
       }
       return get_my_file_from_memory();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to bulk load a large amount of data (about 7.000.000 entries) into
In my Silverlight application, I load all the images I need at application start
I need to have a Win32 application load a hard coded AES-256 key, ideally
I need to write a MultiThreaded Java Application that will be used to load
I need to change database and settings when my customers load the application (xap)
I need to use a dll in my asp.net application. How do I load
In an application I need to execute other programs with another user's credentials. Currently
I am currently trying to load a slightly large xml file into a dataset.
I have a large application spread across multiple Spring bean definition xml files. In
I have a UITabBar Application with two views that load large amounts of data

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.