+ Start a Discussion

Is memory allocated to null or blank fields of the record?




I have an object and it has 10 fields which are null or empty for most of the records. I just wanted to know whether memory is being allocated to these fields or not as there is memory usage limit in the salesforce and I don't want to cross that due to these null or empty fields.





They must be taking space even if they are blank. I will suggest you to use a AppExchange product "FieldTrip" which can generate the reports on the field usages.

Shashikant SharmaShashikant Sharma

Yes memory is allocated to null values as well.


See this For more : http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections_lists.htm

List<Account> accts = new Account[]
         {new Account(), null, new Account()};
Defines an Account list with memory allocated for three Accounts, including a new Account object in the first position, null in the second position, and another new Account object in the third position




Thanks for the reply, I am not asking for the complete record.


I just want to know suppose if there are some existing records of an object and we introduce some new custom fields in the object. So does the memory gets allocated for each field for all the records.




Shashikant SharmaShashikant Sharma

If you have a qurery


Account a = [Select id , Name , CustonField1__c  from Account  where id = '001ksja000ijh'];


now even if a.CustomFIeld__c is null memory is allocated to it.


But if you create a instance


Account a = new Account(Name = 'Test');


here no meory allocated to a.CustonField1__c  


I  hope it is clear now.


I don't think that is correct - if you query back a field which is null, there won't be space taken up with reference to an empty field, the field reference contained by the sobject will simply be null.  The same applies if you instantiate a new sobject and only supply a few fields.


For example,  if you do the following:


Account a = new Account(Name = 'Test');

System.debug('## custom field 1 ' + a.Custom_Field_1__c);

the debug statement will output a null value.  Thus the sobject contains a reference to a field named Custom_Field_1__c, but the value of that reference is null.  


Whenever you create an instance of an sobject, this will contain a reference for every field defined in the schema - there's nothing you can do about this, its effectively part of the "class" for the sobject.  If you then populate a field value, you will create a new field instance "object" that consumes the amount of memory that is required for the field type (small for an Integer, large for a Large Text Area).