...
Code Block | ||
---|---|---|
| ||
public class MyStateObject { // preallocated array to hold values from a message private final ArrayList<MyEntity> myEntities = new ArrayList<MyEntity>(5); public final void update(final Message message) { clearEntities(); XIterator<MyEntity> iterator = message.getMyEntityIterator(); while(iterator.hasNext()) { final MyEntity entity = iterator.next(); if(entity.getQuantity() > 0) { //Acquire a reference since this is owned by the //by the message: entity.acquire(); myEntities.add(entity.copy()); } } } public void clearEntities() { //Dereference and clear previously acquired entities: if(!myEntities.isEmpty()) { for(int i = 0; i < myEntities.size(); i++) { myEntities.get(i).dispose(); } myEntities.clear(); } } } |
Note that the embedded entity copy() method was introduced in the 3.5.1 and 3.6.1 versions of the ADM code generator. Prior versions can use the clone() method, but be advised that the clone operation does not preserve pass-through fields.
Known Limitations
At this time Arrays Accessors for Wrapped primitive types are not zero garbage. This includes String[], Uuid[] and Date[] fields. For zero garbage operation with these types consider using XBuf - Repeated Field Bulk Copies.