Results 1 to 4 of 4
- 05-31-2013, 07:46 AM #1
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!
- 05-31-2013, 08:55 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 07-08-2013, 09:35 PM #3
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!
- 07-08-2013, 10:26 PM #4
Re: Find where anonymous inner class is declared?
That's probably the debug info. See the -g flag in javac - Java programming language compiler .
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
anonymous inner class
By harshit shah in forum AWT / SwingReplies: 2Last Post: 02-11-2013, 06:25 PM -
Does an anonymous class have to extend a class or implement an interface ?
By fatabass in forum New To JavaReplies: 15Last Post: 02-05-2012, 12:15 AM -
how call from inner class(anonymous or not), a method of parent class?
By lse123 in forum AWT / SwingReplies: 2Last Post: 05-01-2010, 09:59 AM -
Name of Anonymous class
By eva in forum New To JavaReplies: 1Last Post: 12-31-2007, 02:07 PM -
Anonymous class
By ravian in forum Advanced JavaReplies: 3Last Post: 12-25-2007, 11:56 AM
Bookmarks