Patent ID: 8589951

Claim:
A computer-implemented method to conserve memory by supporting objects that are selectably mutable during runtime, the method comprising: in response to a first request to seal an object during runtime the object including one or more attributes safeguarding against modification of the object, by operation of one or more computer processors and by sealing the object such that an exception is thrown upon any attempt to modify any of the one or more attributes of the sealed object; and in response to a second request to unseal the sealed object during runtime wherein the first and second requests each specify a respective key, and upon determining that the keys match, unsealing the sealed object such that no exception is thrown upon any attempt to modify any of the one or more of the attributes of the unsealed object; wherein an exception is thrown upon determining that the keys do not match; wherein modification of the object is prevented without having to declare the object as mutable or immutable during compile-time, and while avoiding any memory cost associated with performing defensive copying of the object; wherein selectable mutability of the object is implemented using a predefined seal annotation selected from a runtime seal annotation and a compile-time seal annotation, wherein the predefined seal annotation is applied at a predetermined level selected from a class level of the object and a field level of the object.