Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. General .Net question

General .Net question

Scheduled Pinned Locked Moved C#
questioncsharplounge
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yaakov Davis
    wrote on last edited by
    #1

    Is it enough to hold a delegate to an object method, in order to keep it being collected? And what about reference to some general member? Thanks, Yaakov

    H 1 Reply Last reply
    0
    • Y Yaakov Davis

      Is it enough to hold a delegate to an object method, in order to keep it being collected? And what about reference to some general member? Thanks, Yaakov

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      What exactly are you asking? Do you need to store a reference to a delegate in order to remove it from a event later? If so, the answer is "no". So long as the delegate references the same method for the same instance of a class that is already added to an event (which is a MulticastDelegate), you can "new" up another one like so:

      textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
       
      // Later that day...
       
      textBox1.TextChanged -= new EventHandler(textBox1_TextChanged);

      A delegate is like a managed function pointer. So long as the function pointer (the method to which the delegate points) is the same - the same method on the same instance or a static method for a class - the delegate is the same. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups