Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Difference between Activator.CreateInstance and new

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 23 Sep 2007 18:22 GMT
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
Peter Bromberg [C# MVP] - 23 Sep 2007 19:00 GMT
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

> In both case, using Activator.CreateInstance or new, except for the
> different approach and difference "parameter" required, the final
[quoted text clipped - 8 lines]
> Thanks
> Andrea
Andrew - 24 Sep 2007 10:09 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.