In function header i have this situation:
Should i stay the "=null" in the end, or Java when exiting function do that itself?
My intention it to make this objects as soon as possible ready for garbage collection. This is a soft real time system.
public BulkDataResponse(Double closePrice, Integer closeTime, Integer cmd,
String comments, Double commission, Integer digits,
Integer errorCode, Integer expiration, String login,
Integer magic, Double openPrice, Integer openTime,
Integer positionOrder, Double profit, Double rateClose,
Double rateMargin, Double rateOpen, Integer sourceId,
Double stopLoss, Double swap, String symbol, Double takeProfit,
Double taxes, Integer timeTick, Double volume)
{
super();
this.closePrice = closePrice;
this.closeTime = closeTime;
this.cmd = cmd;
this.comments = comments;
this.commission = commission;
this.digits = digits;
this.errorCode = errorCode;
this.expiration = expiration;
this.login = login;
this.magic = magic;
this.openPrice = openPrice;
this.openTime = openTime;
this.positionOrder = positionOrder;
this.profit = profit;
this.rateClose = rateClose;
this.rateMargin = rateMargin;
this.rateOpen = rateOpen;
this.sourceId = sourceId;
this.stopLoss = stopLoss;
this.swap = swap;
this.symbol = symbol;
this.takeProfit = takeProfit;
this.taxes = taxes;
this.timeTick = timeTick;
this.volume = volume;
closePrice = null;
closeTime = null;
cmd = null;
comments = null;
commission = null;
digits = null;
errorCode = null;
expiration = null;
login = null;
magic = null;
openPrice = null;
openTime = null;
positionOrder = null;
profit = null;
rateClose = null;
rateMargin = null;
rateOpen = null;
sourceId = null;
stopLoss = null;
swap = null;
symbol = null;
takeProfit = null;
taxes = null;
timeTick = null;
volume = null;
}
If you are worried about garbage, I suggest you don't create so much in the first place. Use primitives instead of objects and about half your garbage will disappear. Also you don't need to clear a field which is about to go out of scope anyway. With any luck the JIT is smart enough to remove the code which does do anything.
For high frequency trading system my goal is to create less than one object per price movement on average. This leads to almost no garbage being produced or needing to be cleaned up.
I suggest you consider how you could change your code to remove garbage creation.