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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:58:40+00:00 2026-06-10T18:58:40+00:00

I have a program with a large immutable object that returns a modified version

  • 0

I have a program with a large immutable object that returns a modified version of itself when performing a certain operation. I try to test it in the sbt console, doing something like var myObj = getInitialObject(); and then repeatedly calling myObj = myObj.getNewOne();

There is no reference left to the old object, but the memory doesn’t seem to get freed. Eventually I get an OutOfMemoryError: GC overhead limit exceeded. I was able to reproduce the problem with a simple example at a scala repl prompt:

scala> val foo = List.fill(1000000) { new Object() }
foo: List[java.lang.Object] = List(java.lang.Object@14fd510, java.lang.Object@202d0e1c, java.lang.Object@6df960c4, java.lang.Object@f401c44, java.lang.Object@39ffbc2e, java.lang.Object@449b8dc1, java.lang.Object@40779d17, java.lang.Object@6cea7211, java.lang.Object@13e6f1f4, java.lang.Object@1f16d461, java.lang.Object@13d13c39, java.lang.Object@dc8cc59, java.lang.Object@79dfee20, java.lang.Object@5c8ab562, java.lang.Object@168a6465, java.lang.Object@57c52e72, java.lang.Object@526c6b62, java.lang.Object@4bfe1934, java.lang.Object@1728cbe6, java.lang.Object@776274ea, java.lang.Object@60e9ebe1, java.lang.Object@1d7d327c, java.lang.Object@67d7a04, java.lang.Object@17d59ff0, java.lang.Object@49f751c9, java.lang.Object@c1a890f, java.lang.Object@221c3dfe, java.lang.Object@6c2a0030, java.lang.O...
scala> val foo = List.fill(1000000) { new Object() }
foo: List[java.lang.Object] = List(java.lang.Object@6e8fb561, java.lang.Object@1ccd2bfc, java.lang.Object@6202bc29,.... (ommiting the rest of the output)
scala> val foo = List.fill(1000000) { new Object() }
.... repeat a few more times and get:

scala> val foo = List.fill(1000000) { new Object() }
null

java.lang.OutOfMemoryError: GC overhead limit exceeded
    at scala.tools.nsc.transform.SpecializeTypes$$anonfun$13.apply(SpecializeTypes.scala:669)
    at scala.tools.nsc.transform.SpecializeTypes$$anonfun$13.apply(SpecializeTypes.scala:667)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:200)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:200)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:200)
    at scala.collection.immutable.List.flatMap(List.scala:45)
    at scala.tools.nsc.transform.SpecializeTypes.specializeClass(SpecializeTypes.scala:667)
    at scala.tools.nsc.transform.SpecializeTypes.transformInfo(SpecializeTypes.scala:1065)
    at scala.tools.nsc.transform.InfoTransform$Phase$$anon$1.transform(InfoTransform.scala:38)
.....
....

Using “var” without a re-declaration each time instead of val doesn’t seem to help. How can I get the repl/sbt to free up / garbage collect the memory for that no-longer-relevant object reference?

  • 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-10T18:58:41+00:00Added an answer on June 10, 2026 at 6:58 pm

    As yet, you can’t. https://issues.scala-lang.org/browse/SI-4331

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

Sidebar

Related Questions

I have a large program that is working other then one .h file that
I have a Python program that executes a large MySQL statement. How do I
I have a program that operates on a large set of experimental data. The
I have a program that opens a large binary file, appends a small amount
I have program that is used by 4000 users to search a large database
Have a very large program where there is always a superview that just encompasses
I have a Java program performing some large analysis tasks, running through a loop
I'm running gnome and have a program that spawns off a large number of
I have a program which runs a certain processing suits on a large set
I have a program that can accept a large number of valid arguments. Many

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.