The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to fix java.lang.OufOfMemoryError: Direct buffer memory

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to fix java.lang.OufOfMemoryError: Direct buffer memory Posted: Jan 16, 2014 8:14 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to fix java.lang.OufOfMemoryError: Direct buffer memory
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Java allows application to access non heap memory by using direct byte buffer. Many high performance application uses direct byte buffer, along with memory mapped file for high speed IO. And, while the ByteBuffer object is small itself, it can hold a large chunk of non-heap memory, which is outside of Garbage collection scope.  Which means garbage collector can not reclaim this memory. It is often used to store large data e.g. order or static data cache. Since generally your program allocates large buffer e.g. size of 1GB or 2GB, you get "Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory" error, when you try to allocate memory by running following code

ByteBuffer buffer = ByteBuffer.allocateDirect(SIZE_OF_BUFFER)

java.lang.OutOfMemoryError: Direct buffer memory
    at java.nio.Bits.reserveMemory(Bits.java:632)
    at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:97)
    at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)

Now there could be multiple reasons for that e.g. either your system doesn't have enough heap memory, mostly the case when you are requesting a large chunk of memory, or memory hasn't been free from last usage. First case, is pretty straight forward, as your application will fail to start in first attempt itself, and will not work until you add extra memory or reduce size of direct byte buffer. In second case, there could be either memory leak, where your code is holding reference of ByteBuffer to prevent them from being garbage collected, and subsequently your off heap buffer.

Read more »

Read: How to fix java.lang.OufOfMemoryError: Direct buffer memory

Topic: Grails: Using Hibernate Filters Previous Topic   Next Topic Topic: Git flow with Jenkins and GitLab

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use