Results 1 to 4 of 4
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Find where anonymous inner class is declared?

    Is there an easy way to find where, say, Foo$9 is declared, or do I just have to go through the file and count the inner classes?

    I'm trying to fix a bunch of memory leaks in an Android app, and I can see names of the targets of the threads that are the GC roots for the leaks, but they're mostly anonymous inner classes so it's kind of a pain tracking them down.
    Get in the habit of using standard Java naming conventions!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: Find where anonymous inner class is declared?

    I don't think memory can 'leak' in the traditional way; there's always the garbage collector that reaps memory; memory can be 'sticky' (my own naming), i.e. the memory can still be referenced so the garbage collector keeps its claws far from it. Listeners (observers) are known to be 'sticky' and they are often implemented as anonymous classes indeed. An anonymous class is strictly a compiler thingy, i.e. as far as the jvm is concerned, they don't exist. a.f.a.i.k. you have to count them from the top to the bottom of the enclosing class ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Find where anonymous inner class is declared?

    I found an answer. Run javap on the anonymous inner class file:

    javap -c -verbose 'com.example.MyClass$11' | less

    Then look for the LineNumberTable section:

    LineNumberTable:
    line 1: 0
    line 692: 5


    I'm not sure what all the numbers mean, but the '692' is the line number where this class is declared.
    Get in the habit of using standard Java naming conventions!

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default Re: Find where anonymous inner class is declared?

    That's probably the debug info. See the -g flag in javac - Java programming language compiler .

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. anonymous inner class
    By harshit shah in forum AWT / Swing
    Replies: 2
    Last Post: 02-11-2013, 05:25 PM
  2. Replies: 15
    Last Post: 02-04-2012, 11:15 PM
  3. Replies: 2
    Last Post: 05-01-2010, 08:59 AM
  4. Name of Anonymous class
    By eva in forum New To Java
    Replies: 1
    Last Post: 12-31-2007, 01:07 PM
  5. Anonymous class
    By ravian in forum Advanced Java
    Replies: 3
    Last Post: 12-25-2007, 10:56 AM

Posting Permissions

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