My question is thus this: How much additional memory do member methods within a class add to multiple instances of that class. I am not sure if the JVM genuinely creates a new version of each member method for each class or if it really only creates a single "copy" of the member method and then when that member method is run by an instance of the class, uses that specific instances member variables in the copy. (Note: I am not asking what the Java language claims is done, I am asking what the JVM really does behind the scenes).
Motivation for the question (in case I am asking the wrong question): I am writing a piece of code that will generate pictures of "complicated" mathematical curves, which I am storing in an array. The curves are consturcted iteratively and each iteration causes the number of segments to grow exponentially. Thus (to my limited understanding) the size of the data that represents a segment of the curve is the main limitation on how many iterations the code can go through quickly (i.e. we can't control the number of segments, that is implicit in the problem, but when we are storing so many of them that we run out of memory then the computer has to use the hard drive for memory and substantial slow down takes place). The code should be able to go through as many iterations as quickly as possible. (If we didn't care about speed I expect we could keep the data in a file and load and work with large segments of the data at a time, which is maybe what I should be doing anyway...I don't know if that can be made fast)
Joined: Oct 30, 2001
Methods and their bytecode are associated with the class itself, not with instances of the class. Therefore, having many or complicated methods in a class does not cause an increase in the per-instance memory consumption.
The per-instance memory consumption is a function of the number and type of instance fields.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P