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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:22:48+00:00 2026-05-27T14:22:48+00:00

I have a program that creates an object for each file in a directory

  • 0

I have a program that creates an object for each file in a directory (sub)tree. In these days of larger and larger disks, there is no way to know how many files that will be, esp. not a few years (months?) from now.

My program is not enterprise-critical; it is a tool for a user to analyze that subtree. So it is acceptable to tell the user that there is not enough memory in this environment to operate on that subtree. He could possibly do what he wants by choosing subtrees of that subtree.

But it is not acceptable for the program to just die, or throw a stacktrace, or other things only a programmer can love. I would like the program to give the user some reasonable feedback and let him control what he does about it.

I have read a number of the posts here on StackOverflow about OOM exceptions, and in the main I agree with a number of points: badly designed apps, memory leaks, etc., are all problems that need to be thought of. But in this case, I might have had somebody attempt to use my tool on a 10T disk that just has more files than the program prepared to analyze. And I’m not trying to write the tool so that it operates on every possible subtree.

I have seen suggestions that OOM can just be caught “like any other exception”; unfortunately, this is not a robust way to do things. When OOM gets thrown, some thread is likely to have died already, and we cannot tell which one it will be, and we can’t restart it. So if it happens to be one critical to Swing, for instance, then we are out of luck.

So my current thinking is that my program will need to take occasional looks (at least) at the amount of free memory available and stop itself if that gets below some threshold. I can test things to determine a threshold that allows me to output a dialog box with a message and then wipe all my references to my objects.

But if I’m missing something, or there’s a better way to go about things, I’d like to know it.

  • 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-27T14:22:49+00:00Added an answer on May 27, 2026 at 2:22 pm

    See my post here. Why not calculate freeMemory as you’re populating the tree, and stop at some (possibly user configurable) point like: 90% heap occupied. You should really try to keep the object you create for each file as small as possible. Can you paste the code for this data structure so we can critique it and see if it can be made smaller? Maybe you don’t need to have an object directly, but rather a proxy object that can get the relevant information upon request.

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

Sidebar

Related Questions

I have a program that creates a small file in the Bin directory for
I have a program that creates a JFrame and makes it visible. Is there
I have a program that creates a Windows user account using the NetUserAdd() API
Greetings I have a program that creates multiples instances of a class, runs the
I have a simple program that creates a thread, loops twenty times and then
I have a Delphi program that creates HTML files. Later when a button is
I have a program that starts up and creates an in-memory data model and
Suppose I have an SConstruct file that looks like this: env = Environment() env.Program(a,
I have a program that stores it's information in an XML file. This file
I have a program that reads and draws an SVG file in a java

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.