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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:59:03+00:00 2026-06-02T18:59:03+00:00

So I have an application that allows you to upload documents and images and

  • 0

So I have an application that allows you to upload documents and images and saves these as byte[] in the database.

(I created an minimal example project that you can download as zip here and import into STS http://dl.dropbox.com/u/2342474/byteMemoryLeak.zip… all you have todo is go to the datasource.groovy and change your db settings)

So the domain object looks something like this:

class Test { 

    byte[] data 

    static constraints = { 
        data nullable: false, maxSize: 1024*1024*40 
    } 
} 

and the controller and views are all generated directly with the generate-all command… nothing changed here…

So now when we start the project we go to the test controller… hit create new… upload a document … use something thats like 5 – 10 mb… and hit create…

I expect the memory usage to go up while the save() method is execute and then when the show method is called too… but once those are finished loading GC should pick up those objects and throw them away since they are currently not needed… now i used Your Kit Java Profiler to check the memory usage and i can see that there are 3 reference of my byte[] which have weak reference or are unreachable… why is that? shouldnt they have been removed right when the show() method or save() method complete?

Here a screenshot: [memory leak]: https://i.stack.imgur.com/R7KMt.png

Do I have to make special settings for tomcat to run the gc more often?

I am very confused about this and it actually causes a problem in the application that I have in testing right now cause people are uploading a lot of documents to it and the heap memory just gets fuller and fuller and gets almost never cleaned so that i get at some point an out of memory exception… the same actually happens also in the list() method that it loads all the objects and now actually for each object the byte[] is loaded and now in memory and doesnt get cleaned up…

Maybe I am just missing something or doing something wrong… any help would be greatly appreciated…

Thanks
Chris

  • 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-02T18:59:05+00:00Added an answer on June 2, 2026 at 6:59 pm

    Grails application usually runs with JRE created in server mode which affects how memory works. Basically, when running in “client” mode, then it tries to use less memory and to release it more often, while when running in server mode, JRE tries to use more memory to provide more speed. You can read some discussion here: Real differences between “java -server” and “java -client”

    Basically, JRE will allow heap to grow till its limit and only then it will think about freeing memory.

    I downloaded your example and started it up, then I uploaded same file multiple times. Memory usage of java process grows like this (for each request: 822mb -> 917mb -> 1.03mb, and then it stops. Next uploads did not increase memory usage and no PermGen space exception was thrown.

    So, I think there is no memory leak happening here. What you experiencing is just JRE tries not to run GC until it still can allocate new one (cause generally, running GC is slower then just allocating new memory).

    Hope this helps.

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

Sidebar

Related Questions

We have created a web application, using ASP.NET, that allows users to upload documents
Let say, I have a web application that allows users to upload images and
I have an application that allows users to upload images. The test case I
I have a web application that allows users to upload certain documents relevant to
I have an application that allows users to upload files. Some of these files
I have an android application that allows users to upload images to their account.
I have an application that allows admins to upload files. These files are stored
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,
I have a file upload function in my asp.net mvc application that allows users
we have the following scenario: * a .NET application allows users to upload documents.

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.