Determine byte size of an object in memory

59 views
Skip to first unread message

Philip Hunt (Enigma)

unread,
Oct 12, 2009, 10:49:08 PM10/12/09
to cfugau...@googlegroups.com

Hi all,

 

Does anyone know how to determine the actual byte size of an object in memory?

 

For example, how would I get the byte size of a serialised CFC?

 

 

Philip Hunt

cid:image001.gif@01C78D7A.0D98C230

Phone:     +64 9 912 9108

 

image001.gif

DQ

unread,
Oct 12, 2009, 11:43:46 PM10/12/09
to ColdFusion User Group - New Zealand
Might be possible to write to file perhaps? Check the size?

On Oct 13, 3:49 pm, "Philip Hunt \(Enigma\)"
<Philip.H...@enigma.co.nz> wrote:
> Hi all,
>
> Does anyone know how to determine the actual byte size of an object in
> memory?
>
> For example, how would I get the byte size of a serialised CFC?
>
> Philip Hunt
>
> Phone:     +64 9 912 9108
>
>  image001.gif
> 2KViewDownload

Shama Sukul Lee

unread,
Oct 12, 2009, 11:45:03 PM10/12/09
to cfugau...@googlegroups.com

You can probably take a 'Before Heap Size', instantiate your object, and then take an 'After Heap Size'...maybe?

So using the Java Runtime object from CF:

runtime = CreateObject("java","java.lang.Runtime").getRuntime();
freeMemoryBefore = runtime.freeMemory();
//Create Object here
freeMemoryAfter = runtime.freeMemory();
memUsedByObject = freeMemoryBefore - freeMemoryAfter;

May also need to do Garbage collection before and after to ensure accurate results.

Let me know if that actually works cos have not personally tried it! ;-)



---------------
Shama Sukul Lee | Development Team Leader |
ProjectPartner.com Limited | PO Box 2343, Shortland St | Auckland 1140 |
T: +64 9 361 6500 | F: +64 9 361 6504 | M: +64 21 2673728 |
Skype: shamasukul | LinkedIn | Twitter: @shamasukul |

David Harris

unread,
Oct 13, 2009, 3:47:58 AM10/13/09
to cfugau...@googlegroups.com
I've been playing with the Server monitor a bit.
While it seems to be having issues in production, you could create your object in Application or Session see how big it is?
Reply all
Reply to author
Forward
0 new messages