Difference between Activator.CreateInstance and new

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    #1

    Difference between Activator.CreateInstance and new

    In both case, using Activator.Creat eInstance 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

  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: Difference between Activator.Creat eInstance and new

    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



    "Andrew" wrote:
    In both case, using Activator.Creat eInstance 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
    >
    >

    Comment

    • Andrew

      #3
      Re: Difference between Activator.Creat eInstance and new

      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

      Comment

      Working...