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. Free Memory Question: ApplicationContext holds Form [modified]

Free Memory Question: ApplicationContext holds Form [modified]

Scheduled Pinned Locked Moved C#
comperformancehelpquestion
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.
  • M Offline
    M Offline
    Martin 0
    wrote on last edited by
    #1

    Hello, I found out that my ApplicationContext instance holds a reference of my Splash window (Windows.Forms.Form), so that GC can not free the memory. (MemProfiler[^]told me) It's not a real problem for my program, but I'm curious why. My program is working like his: 1) At startup my splash form is instanciated. 2) An ApplicationContext instance is created, with my splash instance as parameter:

      AppContext = new ApplicationContext(\_splash);
      Application.Run(AppContext);
    
    1. Startup continious (instanciates classes like mainwindow and so on) and feeds splash with information to show. 4) Startup finished 5) Now my mainwindow is linked to the ApplicationContext and replaces the splash form.

      AppContext.MainForm = _mainwindow;
      _mainwindow.Show();

    2. Splash is closed and local references which are linked to the splash class got disposed.

      _splash.Close();
      _splash = null;
      .
      .

    It looks to me that in "5)" I'm doing something unsufficiant, so that AppContext still holds the ref to the splash. I'm open for all suggestions. Thanks for your time. All the best, MArtin -- modified at 5:38 Wednesday 13th June, 2007 The ApplicationContext holds the reference to the Splash form over the Application.ThreadContext.RunMessageLoopInner method, where the instance is passed as an argument.

    L 1 Reply Last reply
    0
    • M Martin 0

      Hello, I found out that my ApplicationContext instance holds a reference of my Splash window (Windows.Forms.Form), so that GC can not free the memory. (MemProfiler[^]told me) It's not a real problem for my program, but I'm curious why. My program is working like his: 1) At startup my splash form is instanciated. 2) An ApplicationContext instance is created, with my splash instance as parameter:

        AppContext = new ApplicationContext(\_splash);
        Application.Run(AppContext);
      
      1. Startup continious (instanciates classes like mainwindow and so on) and feeds splash with information to show. 4) Startup finished 5) Now my mainwindow is linked to the ApplicationContext and replaces the splash form.

        AppContext.MainForm = _mainwindow;
        _mainwindow.Show();

      2. Splash is closed and local references which are linked to the splash class got disposed.

        _splash.Close();
        _splash = null;
        .
        .

      It looks to me that in "5)" I'm doing something unsufficiant, so that AppContext still holds the ref to the splash. I'm open for all suggestions. Thanks for your time. All the best, MArtin -- modified at 5:38 Wednesday 13th June, 2007 The ApplicationContext holds the reference to the Splash form over the Application.ThreadContext.RunMessageLoopInner method, where the instance is passed as an argument.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi Martin, I have no experience wirth ApplicationContext; I once did a splash screen without it. But I just read an article[^] on it, it may interest you. Now I discovered same article here ![^] Regards,

      Luc Pattyn [My Articles] [Forum Guidelines]

      M 2 Replies Last reply
      0
      • L Luc Pattyn

        Hi Martin, I have no experience wirth ApplicationContext; I once did a splash screen without it. But I just read an article[^] on it, it may interest you. Now I discovered same article here ![^] Regards,

        Luc Pattyn [My Articles] [Forum Guidelines]

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        Hello Luc, Thanks for the links. I will go threw them and let you know if it helped. All the best, Martin

        1 Reply Last reply
        0
        • L Luc Pattyn

          Hi Martin, I have no experience wirth ApplicationContext; I once did a splash screen without it. But I just read an article[^] on it, it may interest you. Now I discovered same article here ![^] Regards,

          Luc Pattyn [My Articles] [Forum Guidelines]

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Hello Luc, Again, thanks for your time! I downloaded the source of the article you provided, and found out that there is exactly the same happening as in my project. Apart from that the article shows very well how a inherited ApplicationContext class can be modified for the Splash usage. So thanks for the link! I also posted the question in the article, maybe the autor is interested in that fact. All the best, Martin

          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