Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion memory usage for Components

I am creating a site using VMC and using beans to transfer the data from the Model to the Controller/Views.

I plan to implement some basic and very simple caching that will store the beans in a simple struct if they have not changed (as usage grows, we will implement a better caching system around ver 1.3).

So the question goes to what goes in our bean.

One type of bean would only hold the basic data and would rely on some outside service to do the rest of the work (contacting the DAO to get the query, parsing the query to load the bean values). This is the "anemic bean" model as I have been told repeatedly by a co-worker :-).

Another type of bean would be more self-contained. It would know where the DAO is so would call the DAO directly to get the data query. It would contain necessary functions to parse out the query and set the properties. It would basically combine much of the "service" layer with the bean, leaving the direct database in the DAO layer.

Of course, to the controller/views, both beans would look and act the same.

But the question is memory and how ColdFusion/Java deals with it.

With the anemic model, the bean would just have enough memory to hold the property variables with just a touch more to let it point to the Service when it needs to.

With the heavier functions in the second type bean, would it take up more memory in the cache??? Would each copy of the bean have a full copy of the methods?

I tend to think that the second model would not have much more memory since they would "share" the methods and would only need memory for the property variables.

IMHO the second method would simplify the codebase, since the code the bean needs would be closer to the bean rather than scattered between the DAO and Services. And it would reduce simple functions in the Service that merely pass along calls to the DAO of the bean could go directly to the DAO when it needed it...

Does the question make sense?? Or at least how I am asking it?

like image 361
Stephen F Roberts Avatar asked Dec 31 '12 01:12

Stephen F Roberts


1 Answers

All the memory management is handed at Java level, so it follows the same rules. In Java the only "new" memory that's allocated when an object instance is created is for its member variables; there is not memory foot print for the methods of the component/class itself: that stuff is only stored in memory once, with a reference back to it.

One possible consideration is that each method of a CFC is compiled as its own discrete class (why? I don't know), so each method is its own class. This will perhaps mean a slightly larger memory footprint for CFC usage compared to Java class usage, but this will still not be something that scales with object-instantiation: each instance of an object will still just consume memory for its member variables, not the methods of the CFC that defines the object.

like image 120
Adam Cameron Avatar answered Oct 23 '22 04:10

Adam Cameron