Difference between Activator.CreateInstance and new

A

Andrew

In both case, using Activator.CreateInstance or new, except for the
different approach and difference "parameter" required, the final
result should be the same, a specific object type ready to be used
along with its method and function. Isn't it?

Supposing a sort of "Initialize" method of a super class that contain
for instance 25 vars for 25 different subclasses and in this
Inizitialize method I create a new instance for every class, doesn't
this waste memory or resource?

Thanks
Andrea
 
G

Guest

I think it is really a question of "Do I *need* 25 instances of various
classes when I create an instance of the 'super' class'." If that is the
actual case, then since you really need them, no it would not be a waste of
memory.
You have various techniques such as lazy initialization that come into play.
It all depends on what your business logic demands.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
 
A

Andrew

Certainly a mechanism of lazy load should be implemented ... I was
focusing just on the best way ... to understand which implement.
Some tests reports a faster load using reflection ... but maybe I
don't understand it correctly.

Andrea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top