Difference between Activator.CreateInstance and new

  • Thread starter Thread starter Andrew
  • Start date Start date
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
 
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
 
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
 
Back
Top