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. WPF
  4. Remove Control

Remove Control

Scheduled Pinned Locked Moved WPF
performance
4 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.
  • R Offline
    R Offline
    RishiKasnia
    wrote on last edited by
    #1

    i have created a user control Dynamically and added it to a Wrap Panel as a child. now if i remove it from panel but it still remains in memory. i want it to be permanently removed from memory. There is no Dispose method available. and i also tried by implementing idisposable interface and overwriting the Dispose() method for my control but it still remain in memory. Is there any way to remove this object(User Control) from memory Regards Rishi

    P 1 Reply Last reply
    0
    • R RishiKasnia

      i have created a user control Dynamically and added it to a Wrap Panel as a child. now if i remove it from panel but it still remains in memory. i want it to be permanently removed from memory. There is no Dispose method available. and i also tried by implementing idisposable interface and overwriting the Dispose() method for my control but it still remain in memory. Is there any way to remove this object(User Control) from memory Regards Rishi

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      RishiKasnia wrote:

      Is there any way to remove this object(User Control) from memory

      Nope. WPF uses MIL handles internally, and the garbage collector is called as and when it is needed. When you think about it, this makes perfect sense - the whole point of WPF is that it doesn't need you to access unmanaged resources to do things (you can, but you aren't required to) so you don't actually need to Dispose controls.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      My blog | My articles | MoXAML PowerToys

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        RishiKasnia wrote:

        Is there any way to remove this object(User Control) from memory

        Nope. WPF uses MIL handles internally, and the garbage collector is called as and when it is needed. When you think about it, this makes perfect sense - the whole point of WPF is that it doesn't need you to access unmanaged resources to do things (you can, but you aren't required to) so you don't actually need to Dispose controls.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        My blog | My articles | MoXAML PowerToys

        R Offline
        R Offline
        RishiKasnia
        wrote on last edited by
        #3

        Thanks Pete for reply but in my case i need to remove this user control from memory . becoz after removing it from canvas or panel , if i try to fire some event then this Control also respond the event (Though it has been removed). for a workaround i detached the Event Handler for user control(when i remove it from canvas/panel). but it still resides in memory and remains throughout the program execution (becoz this control is not local to any Block) thus degrading performance . Regards Rishi.

        P 1 Reply Last reply
        0
        • R RishiKasnia

          Thanks Pete for reply but in my case i need to remove this user control from memory . becoz after removing it from canvas or panel , if i try to fire some event then this Control also respond the event (Though it has been removed). for a workaround i detached the Event Handler for user control(when i remove it from canvas/panel). but it still resides in memory and remains throughout the program execution (becoz this control is not local to any Block) thus degrading performance . Regards Rishi.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Unfortunately you can't automatically remove the control deterministically. You could, possibly, remove the control by forcing a garbage collection, but this really is a bad idea.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          My blog | My articles | MoXAML PowerToys

          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