Can you explain, what difference in using memory between using Object[][] and Iterator<Object[]> in data provider.
When you work with a data provider that returns a 2D Object array ( Object[][] ), TestNG calls the data provider and the data provider ends up creating the entire 2D array in 1 shot. So for example, lets say your data driven test method accepts 1 integer as parameter, and you return 10,000 rows, so here we end up occupying memory worth 10,000 * 4bytes = 40kb even before the test starts running.
If you leverage a data driven test method that is powered by a data provider which returns Iterator<Object[]> then you aren't allocating that much memory in one shot. TestNG gets the Iterator and for each of the 10,000 iterations, you will consume 4bytes incrementally.
Depending upon your reporting requirements, there's a very good chance that you will still end up with a bloated memory, because TestNG remembers all the parameters of all the test methods (along with the corresponding java.lang.reflect.Method objects) for all your 10,000 iterations and so, by the time your test execution is done and you are in your reporting phase, you may still hit an OutOfMemoryError.
The JVM argument that I shared in my previous post, will atleast avoid taking the extra memory occupied by each of the 10k java.lang.reflect.Method references (It might not be an issue because it's the same method reference in all the 10k invocations, but I hope you get the idea)