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. Managed C++/CLI
  4. Forcing GC

Forcing GC

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestionc++htmldotnet
17 Posts 3 Posters 40 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.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    Hello, I have an MFC program (/clr) that is a remoting client. My issue is that once we have got our remote object, then for some wacko reasons as yet unknown to me, I am unable to create a view for a frame window. The Create just fails. My solution to this was to create the window and hide it before the remote object was obtained and then to show/hide it as required. But the issue is that sometimes the user can do something where the remote object is created, then he goes back to the main window, then he comes back to this window where the remote frame/view is created. Now if the GC is given enough time to destroy the unused object, everything is fine. But my problem is that the GC is sorta slow on all this and I am having problems. So, how do I force the GC to destroy the remote object? And what do I do if the GC fails to recognize the object as unused and thus fails to free it? Is there anyway I can simulate a delete on a managed object? Regards, Nish


    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

    R J 2 Replies Last reply
    0
    • N Nish Nishant

      Hello, I have an MFC program (/clr) that is a remoting client. My issue is that once we have got our remote object, then for some wacko reasons as yet unknown to me, I am unable to create a view for a frame window. The Create just fails. My solution to this was to create the window and hide it before the remote object was obtained and then to show/hide it as required. But the issue is that sometimes the user can do something where the remote object is created, then he goes back to the main window, then he comes back to this window where the remote frame/view is created. Now if the GC is given enough time to destroy the unused object, everything is fine. But my problem is that the GC is sorta slow on all this and I am having problems. So, how do I force the GC to destroy the remote object? And what do I do if the GC fails to recognize the object as unused and thus fails to free it? Is there anyway I can simulate a delete on a managed object? Regards, Nish


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #2

      Nishant S wrote: The Create just fails. What is the error. What does ERR,hr say? Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

      N 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        Nishant S wrote: The Create just fails. What is the error. What does ERR,hr say? Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Rama Krishna wrote: What is the error. What does ERR,hr say? The view is a CHtmlView derived view and the call to Create returns false :-( I think once we've got a remote object, for some reasons we cannot create webbrowser controls. Because my Create call in the CFrameWnd derived class didn't fail, it was only the view creation in the CFrameWnd::OnCreate that fails :-( Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

        R 1 Reply Last reply
        0
        • N Nish Nishant

          Rama Krishna wrote: What is the error. What does ERR,hr say? The view is a CHtmlView derived view and the call to Create returns false :-( I think once we've got a remote object, for some reasons we cannot create webbrowser controls. Because my Create call in the CFrameWnd derived class didn't fail, it was only the view creation in the CFrameWnd::OnCreate that fails :-( Nish


          Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

          R Offline
          R Offline
          Rama Krishna Vavilala
          wrote on last edited by
          #4

          Are you initialzing COM correctly - CoInitialize(NULL) ? [EDIT] Since you are using MFC are you calling AfxOleInit ? Nishant S wrote: Create returns false Put ERR,hr is watch window it will show you the reason why it failed. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

          N 1 Reply Last reply
          0
          • N Nish Nishant

            Hello, I have an MFC program (/clr) that is a remoting client. My issue is that once we have got our remote object, then for some wacko reasons as yet unknown to me, I am unable to create a view for a frame window. The Create just fails. My solution to this was to create the window and hide it before the remote object was obtained and then to show/hide it as required. But the issue is that sometimes the user can do something where the remote object is created, then he goes back to the main window, then he comes back to this window where the remote frame/view is created. Now if the GC is given enough time to destroy the unused object, everything is fine. But my problem is that the GC is sorta slow on all this and I am having problems. So, how do I force the GC to destroy the remote object? And what do I do if the GC fails to recognize the object as unused and thus fails to free it? Is there anyway I can simulate a delete on a managed object? Regards, Nish


            Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

            J Offline
            J Offline
            James T Johnson
            wrote on last edited by
            #5

            System::GC::Collect() James "Java is free - and worth every penny." - Christian Graus

            N 1 Reply Last reply
            0
            • R Rama Krishna Vavilala

              Are you initialzing COM correctly - CoInitialize(NULL) ? [EDIT] Since you are using MFC are you calling AfxOleInit ? Nishant S wrote: Create returns false Put ERR,hr is watch window it will show you the reason why it failed. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              Rama Krishna wrote: Are you initialzing COM correctly - CoInitialize(NULL) ? Not using any COM, not much anyway!!! [Just a few lines to get the underlying web browser control and to set the html] Rama Krishna wrote: Since you are using MFC are you calling AfxOleInit ? Hmmm. Nope. I mean I am not calling it on my own. Dunno if that might be the problem. Because the window creation (frame and view) succeeds *if* the remote object is not obtained. It fails *only* if we have obtained the remote object very puzzling, very puzzling indeed! Anyway it's part of a work-time tracking system app that I'll be submitting to CP soon, if I can only get rid of this goddamn error :-( Rama Krishna wrote: Put ERR,hr is watch window it will show you the reason why it failed. Huh? Just like that --- "Err,hr" :confused:


              Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

              R 2 Replies Last reply
              0
              • J James T Johnson

                System::GC::Collect() James "Java is free - and worth every penny." - Christian Graus

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #7

                James T. Johnson wrote: System::GC::Collect() Thanks Jambo. I'll try that. But what if the GC fails to recognize the unused object as a free one. How do I tell the GC that this object is now free. Will setting it to point to NULL help in freeing the now-orphaned object??? Nish


                Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                J 1 Reply Last reply
                0
                • N Nish Nishant

                  Rama Krishna wrote: Are you initialzing COM correctly - CoInitialize(NULL) ? Not using any COM, not much anyway!!! [Just a few lines to get the underlying web browser control and to set the html] Rama Krishna wrote: Since you are using MFC are you calling AfxOleInit ? Hmmm. Nope. I mean I am not calling it on my own. Dunno if that might be the problem. Because the window creation (frame and view) succeeds *if* the remote object is not obtained. It fails *only* if we have obtained the remote object very puzzling, very puzzling indeed! Anyway it's part of a work-time tracking system app that I'll be submitting to CP soon, if I can only get rid of this goddamn error :-( Rama Krishna wrote: Put ERR,hr is watch window it will show you the reason why it failed. Huh? Just like that --- "Err,hr" :confused:


                  Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                  R Offline
                  R Offline
                  Rama Krishna Vavilala
                  wrote on last edited by
                  #8

                  Nishant S wrote: Not using any COM, not much anyway!!! You need to initialize COM by calling AfxOleInit if you are using the webbrowser control. That is why Create fails. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

                  N 1 Reply Last reply
                  0
                  • N Nish Nishant

                    James T. Johnson wrote: System::GC::Collect() Thanks Jambo. I'll try that. But what if the GC fails to recognize the unused object as a free one. How do I tell the GC that this object is now free. Will setting it to point to NULL help in freeing the now-orphaned object??? Nish


                    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                    J Offline
                    J Offline
                    James T Johnson
                    wrote on last edited by
                    #9

                    Yes, you need to set it to NULL. However it would be prudent to follow Rama's thread and get to the root of the problem instead of a hack to work around what is a bug somewhere in your code. James "Java is free - and worth every penny." - Christian Graus

                    N 1 Reply Last reply
                    0
                    • N Nish Nishant

                      Rama Krishna wrote: Are you initialzing COM correctly - CoInitialize(NULL) ? Not using any COM, not much anyway!!! [Just a few lines to get the underlying web browser control and to set the html] Rama Krishna wrote: Since you are using MFC are you calling AfxOleInit ? Hmmm. Nope. I mean I am not calling it on my own. Dunno if that might be the problem. Because the window creation (frame and view) succeeds *if* the remote object is not obtained. It fails *only* if we have obtained the remote object very puzzling, very puzzling indeed! Anyway it's part of a work-time tracking system app that I'll be submitting to CP soon, if I can only get rid of this goddamn error :-( Rama Krishna wrote: Put ERR,hr is watch window it will show you the reason why it failed. Huh? Just like that --- "Err,hr" :confused:


                      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                      R Offline
                      R Offline
                      Rama Krishna Vavilala
                      wrote on last edited by
                      #10

                      I forgot to mention that you also need to call AfxEnableControlContainer. Nishant S wrote: Huh? Just like that --- "Err,hr" Yes. It is a very cool feature. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

                      N 1 Reply Last reply
                      0
                      • J James T Johnson

                        Yes, you need to set it to NULL. However it would be prudent to follow Rama's thread and get to the root of the problem instead of a hack to work around what is a bug somewhere in your code. James "Java is free - and worth every penny." - Christian Graus

                        N Offline
                        N Offline
                        Nish Nishant
                        wrote on last edited by
                        #11

                        James T. Johnson wrote: However it would be prudent to follow Rama's thread and get to the root of the problem instead of a hack to work around what is a bug somewhere in your code. I am trying to, Jambo! I really am!! The annoying thing is that everything works fine if I don't obtain the remoted object. After that everything falls down :-( Nish


                        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                        1 Reply Last reply
                        0
                        • R Rama Krishna Vavilala

                          Nishant S wrote: Not using any COM, not much anyway!!! You need to initialize COM by calling AfxOleInit if you are using the webbrowser control. That is why Create fails. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

                          N Offline
                          N Offline
                          Nish Nishant
                          wrote on last edited by
                          #12

                          Rama Krishna wrote: You need to initialize COM by calling AfxOleInit if you are using the webbrowser control. That is why Create fails. Alright, then how does Create succeed when I don't obtain the remote object? Nish :confused:


                          Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                          J R 2 Replies Last reply
                          0
                          • R Rama Krishna Vavilala

                            I forgot to mention that you also need to call AfxEnableControlContainer. Nishant S wrote: Huh? Just like that --- "Err,hr" Yes. It is a very cool feature. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

                            N Offline
                            N Offline
                            Nish Nishant
                            wrote on last edited by
                            #13

                            Rama Krishna wrote: Yes. It is a very cool feature. Damnation!!!!!!! Err,hr is S_OK Means there was no COM error. Yet the call to Create has failed!!! Have I discovered a bug????????? Sucks!!!!!!!!!! Nish


                            Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                            1 Reply Last reply
                            0
                            • N Nish Nishant

                              Rama Krishna wrote: You need to initialize COM by calling AfxOleInit if you are using the webbrowser control. That is why Create fails. Alright, then how does Create succeed when I don't obtain the remote object? Nish :confused:


                              Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                              J Offline
                              J Offline
                              James T Johnson
                              wrote on last edited by
                              #14

                              I'm going to go out on a limb and say that it initializes COM for you and either MFC doesn't get to do its initialization or that it initializes it with settings incompatible with the web browser control. Just a guess :) James "Java is free - and worth every penny." - Christian Graus

                              N 1 Reply Last reply
                              0
                              • J James T Johnson

                                I'm going to go out on a limb and say that it initializes COM for you and either MFC doesn't get to do its initialization or that it initializes it with settings incompatible with the web browser control. Just a guess :) James "Java is free - and worth every penny." - Christian Graus

                                N Offline
                                N Offline
                                Nish Nishant
                                wrote on last edited by
                                #15

                                James T. Johnson wrote: I'm going to go out on a limb and say that it initializes COM for you and either MFC doesn't get to do its initialization or that it initializes it with settings incompatible with the web browser control. What does that mean? Nish :confused:


                                Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                                1 Reply Last reply
                                0
                                • N Nish Nishant

                                  Rama Krishna wrote: You need to initialize COM by calling AfxOleInit if you are using the webbrowser control. That is why Create fails. Alright, then how does Create succeed when I don't obtain the remote object? Nish :confused:


                                  Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                                  R Offline
                                  R Offline
                                  Rama Krishna Vavilala
                                  wrote on last edited by
                                  #16

                                  Nishant S wrote: Alright, then how does Create succeed when I don't obtain the remote object? Instead of speculating over and over, it will be useful if you add those two lines of code and see whether stuff works. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

                                  N 1 Reply Last reply
                                  0
                                  • R Rama Krishna Vavilala

                                    Nishant S wrote: Alright, then how does Create succeed when I don't obtain the remote object? Instead of speculating over and over, it will be useful if you add those two lines of code and see whether stuff works. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

                                    N Offline
                                    N Offline
                                    Nish Nishant
                                    wrote on last edited by
                                    #17

                                    Rama Krishna wrote: Instead of speculating over and over, it will be useful if you add those two lines of code and see whether stuff works. Yeah, I added them and it works now :-O


                                    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

                                    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