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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:28:53+00:00 2026-06-09T12:28:53+00:00

I am running a multithreaded application with 3 threads: Main Thread – Vector List

  • 0

I am running a multithreaded application with 3 threads:

  • Main Thread – Vector List to store Objects
  • AdderThread – Add Objects to this Vector List
  • RemoverThread – Remove Objects with vectorList.clear() method (synchronized)

Application runs fine but after few hours it gives OutOfMemoryError.

I generated Heap dump and analysed with eclipse MAT which shows vectorList class taking all the memory.

Does clear method free memory which was occupied by individual objects ?

How to fix this?

  • 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-09T12:28:54+00:00Added an answer on June 9, 2026 at 12:28 pm

    If you are adding tasks faster than you are freeing them, you will get an OutOfMemoryError as your Vector will grow to the limit of your memory.

    Instead of using a Vector for a work queue, I suggest using a BlockingQueue from the concurrency libraries.

    e.g.

    BlockingQueue<Work> queue = new ArrayBlockingQueue<>(MAX_TASKS_WAITING);
    
    AdderThread calls queue.put(work); // blocks if the queue is full
    
    RemoverThread call queue.take(); // blocks if there is nothing to do.
    

    In fact it would be much simpler to use an ExecutorService as this combines a work queue with a thread pool. You submit tasks to the executor and it processes them. This avoids the need to write any code for the RemoverThread as such.

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

Sidebar

Related Questions

This issue has come up in a distributed-multithreaded application I'm developing, where threads can
I have a multithreaded application running on Win XP. At a certain stage one
I have a multithreaded WPF application that is using > 600 threads after is
I have an application that I'm trying to make multithreaded. Each thread will access
I'm trying to find the handle of the main thread of an external application.
I have a multithreaded application, where each thread has a variable of integer type.
I am developing a multithreaded application that makes use of POSIX Threads . I
We have a WinForms desktop application, which is heavily multithreaded. 3 threads run with
I have done strace on my multi-threaded c++ application running on linux after couple
I have a long-running multithreaded program, and I'd like to occasionally like to call

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.