I have a logic where I am looping though a queryRun object in class A and inside the loop I am calling class B and passing the table records of the query as parameters:
Logic of class A:
public void run()
{
ClassB classB = ClassB::construct();
while (queryRun.next())
{
if (queryRun.changed(tableNum(InventTable)))
{
InventTable inventTable = queryRun.get(tableNum(InventTable));
EcoResCategory ecoResCategory = queryRun.get(tableNum(EcoResCategory));
classB.createDefails(inventTable,
ecoResCategory);
}
}
}
Logic of class B:
public void createDetails(InventTable _inventTable, EcoResCategory _ecoResCategory)
{ //line 7
inventTable.clear(); //line8
ecoResCategory.clear(); //line9
inventTable = _inventTable;
ecoResCategory = _ecoResCategory;
//processing logic
}
In class B, I have global variables InventTable and EcoResCategory which will be used. I have added a logic in class B's createDetails to clear those 2 variables. However, I have a very weird behaviour where upon clearing those 2 variables of class B, the variables passed as parameters (_inventTable and _ecoResCategory) are also being cleared. It works fine when the logic of createDetails is executed for the first loop, but then for the following loops both the global variables and parameter variables become null after the line 9 execution. When debugging, _inventTable and _ecoResCategory have their respective records at line 7 but then they become null after line 9.
I have commented line 8 and 9 and it works fine now but I could not understand why they were causing this issue.
Has anyone had this issue before?