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 8728711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:42:08+00:00 2026-06-13T08:42:08+00:00

I need to have a large list of data that when referenced at a

  • 0

I need to have a large list of data that when referenced at a specific location calculates (loads from a file, and/or generates it if it hasn’t been generated yet) and keeps it for future use. This is powered by lazy lists bound to a function. These “chunks” sometimes are loaded but never really used after that while still effectively referenced in code so the GC doesn’t pick up on them.

Since the RAM quickly fills up, I’d like to lazily unload these chunks after a period of time where they aren’t used by anything. Is this possible?

  • 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-13T08:42:09+00:00Added an answer on June 13, 2026 at 8:42 am

    You can implement this by using unsafeInterleaveIO to read the chunks and periodically going through the list and removing the references to chunks that were not used for a long time (alternatively: use weak pointers as @nponeccop suggests in the comments), but I’d go with something that doesn’t rely on GC for managing memory for the chunks (since predictable memory usage is important for you).

    For example:

    import Data.HashTable.IO
    
    type ChunkMap = BasicHashTable ChunkId (Maybe Chunk)
    
    newChunkMap :: IO ChunkMap
    getChunk :: ChunkMap -> IO Chunk
    freeUnusedChunks :: ChunkMap -> IO ()
    

    where getChunk allocates the memory for missing chunks with malloc and freeUnusedChunks goes through the table and frees unused chunks.

    You can even run freeUnusedChunks in a separate thread:

    freeThread = forever $ do
                     withChunkMapLock $ do
                         freeUnusedChunks map
                         threadDelay 5000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a large list of static data from a server that i load
So I have to take information from a large data file that has 14
I have a large file, with 1.8 million rows of data, that I need
I have a large list [[1,.., ..],[2,...,...],[5,...,...],[1,...,...]] I need to remove all elements that
I have a large .txt file of records that I need to convert into
I have a large text file I am reading from and I need to
I have a large list of instructions that I need executed sequentially but slowly.
I have a large array of numerical data that I need to sort, insert,
I need some help to store some data efficiently. I have a large list
I have a large amount of data that I am pulling from an xml

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.