Results 1 to 4 of 4
  1. #1
    Sanjeev is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Unhappy Getting exception java.lang.OutOfMemoryError: Can't allocate C string

    I am using Java Nativ Access(JNA) calls to access C API. I have defined few few classes, extending com.sun.jna.Structure, correspondent to C structures defined in API.
    I am able to make few calls using jna but it started throwing exception on one of the method.

    with exception trace.

    Exception in thread "main" java.lang.OutOfMemoryError: Can't allocate C string
    at com.sun.jna.NativeLibrary.findSymbol(Native Method)
    at com.sun.jna.NativeLibrary.getSymbolAddress(NativeL ibrary.java:380)
    at com.sun.jna.Function.<init>(Function.java:176)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrar y.java:344)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrar y.java:324)
    at com.sun.jna.Library$Handler.invoke(Library.java:20 3)
    at $Proxy0.mcd_qry_devices_f(Unknown Source)
    at com.kpit.mcd.jna.Main.main(Main.java:38)

    I googled a lot but not finding the proper solution.
    I increased heap memory and native method stack of JVM but had no luck.

    Please reply me if you have any clue or suggestion.
    -Sanjeev

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Try using a profiler to find if/where you have a memory leak.

  3. #3
    Sanjeev is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for quick reply.
    I used YourKit profiler for finding the memory leak. But I observed strange behaviour; when I run my application with profiler(attached profiler with VM) the out of memory error did not appear and it run without any issue. However, when I run the same application without profiler it is throwing same out of memory error.

    It gives me the impression that profiler is some how(by setting some VM arguments) expanding the native memory area that's why it VM is not getting out of memory.
    Last edited by Sanjeev; 07-05-2011 at 03:45 PM. Reason: spell correction

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, for one, you do not want to do anything with com.sun.jna.Structure (or nearly any other com.sun class). That class is a Sun JDK/JRE internal class and is subject to change at any time without notice, thereby ruining your program. Find a JNI tutorial and learn how to use JNI properly.

Similar Threads

  1. Replies: 2
    Last Post: 05-24-2011, 07:18 AM
  2. Replies: 4
    Last Post: 06-03-2010, 08:40 AM
  3. Replies: 10
    Last Post: 05-11-2009, 11:56 AM
  4. Replies: 3
    Last Post: 04-22-2009, 08:25 PM
  5. Replies: 14
    Last Post: 06-12-2008, 08:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •