User Interface | SmartSync | GenericSync | Persistence | Trace | General Programming Tips
| Recommendation |
Description |
| Careful instantiation of objects. | The CrEme virtual machine uses more resources for emory allocation and object instantiation than the Win32 standard Sun VM. The following example shows an unnecessary instantiation:
Reason: If the quantity value is not set, a constant quantity of 0 (represented
as a FixedDecimal) will be assigned. The FixedDecimal object is not defined
as a constant so it will be instantiated every time. This is resource
consuming, especially with a FixedDecimal object. Solution: Define constant values as constants (final static) and try to instantiate objects once and reuse them as often as possible. However, excessive saving of objects can have a negative affect on the memory consumption. |
| Use StringBuffer instead of string concatenation. | Concatenation of more than 2 Strings with the + Operator in frequently called methods is very resource consuming. This is a general Java issue. When concatenating Strings with + a new String Object is instantiated, together with memory-allocation for the underlying char array, for every single concatenation. Example: Following command instantiates 9 objects and allocates char-arrays. String s = “hello ” + “world ” + “here ” + “I “ + “am “; Example: Ineffective way to a add trailing spaces.
|