Why is the first part of my program slowing down the second part? Slow garbage collection?

My program looks like this:

String intermediateResult = foo(int depth, String input);
String finalResult = bar(intermediateResult);

      

-> 'foo ()' connects to postgres database and creates trees and graphs based on input and specified depth, higher depth results in longer computation time and more memory usage of foo as more complex data structures will be inline

-> 'bar ()' prints the result of 'foo ()' which resembles an SQL query and performs several database operations, mainly checking the result of 'foo ()'

QUESTION:

Why does the computation time of "bar ()" depend on the computation depth of "foo ()" even though the same intermediate result is returned? Is Java garbage collection taking longer to clean up data left behind by "foo ()"? Or is it because of the database?

+3


source to share





All Articles