Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question about "new"

 
aaron UD
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using this statement in a while loop:

LDAPAttribute ldapAttr = new LDAPAttribute(attrName, attrValue);

I need to do this because the LDAPAttribute class does not have any "set" functions (i think). There are several other statements like this in the loop as well. My question is: does this eat up a lot of memory? My program is taking a really long time, and I was wondering if this is because the memory that was previously allocated for 'ldapAttr' is not being properly taken care of when the "new" operator is used. thanks a lot.
[ May 02, 2005: Message edited by: aaron UD ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The memory for your first LDAPAttribute should be meaningless, when the loop is iterated the second time.

does this eat up a lot of memory?

It depends on the size of an LDAPAttribute and the other new generated objects - which should be ready for gc, when the loop is iterated a second time, if I understood your idea of using a setter-method instead right: the objects only live in the body of the loop.

How often do you loop? (Some people think that 200 times is often.)
How many objects are created?
How fast is the hosting machine?
Do you do a lot of System.out? Other IO? JDBC?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that those String references passed to the constructor are not part of the memory footprint - they are probably references to String pool objects. Therefore the attribute object is going to be quite small. I would bet on database access as the source of your delay.
However, when in doubt - instrument! Use System.currentTimeMillis for example...
Bill
 
aaron UD
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...thanks for the responses, guys. i am iterating close to 30,000 times. i am using only one LDAPAttribute object, but i am redefining it using 'new' 5 times throughout the loop. so overall, its about 150,000 uses of 'new' for the same variable. as far as I/O, the only that is done inside the loop is just a notification for every 200 iterations. the program slows down on a curve...it starts very quickly, then slows down more and more as the program runs (i can tell because of the output).

I think you are correct in your guess about the delay being due to database access, but the nature of the slowdown is confusing me. any more help would be greatly appreciated.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aaron UD:
i am using only one LDAPAttribute object, but i am redefining it using 'new' 5 times throughout the loop. so overall, its about 150,000 uses of 'new' for the same variable.


Just to clarify the terminology, every "new" creates a new object, which then gets referenced by your variable, which is just a reference to an object.

I doubt that this is your bottleneck, though.


I think you are correct in your guess about the delay being due to database access, but the nature of the slowdown is confusing me. any more help would be greatly appreciated.


P6Spy is a nice free tool to analyze db performance problems. To analyze your java code, you'd probably use some profiler...
 
aaron UD
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,

i think my problem is taken care of. i put the objects in an ArrayList, then cleared the list at the beginning of each iteration. this seems to have done the trick. thanks for your help...

-aaron
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aaron UD:
it starts very quickly, then slows down more and more as the program runs (i can tell because of the output).
Glad to hear you solved the issue. I'd just like to point out output to the console can be very slow. You'd be amazed at how much a program speeds up if you minimize/hide the window and only show it every so often to check on progress.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!