2

I am developing WPF - Web browser control based kiosk application.

I have implemented the feature like when somebody clicks on any textbox inside the page rendered in wpf web browser control then onscreen keyboard will open.

But the code which I have implemented is causing the continuous memory leak.

please find sample files here

Please refer below document to get more detail on issue.

for more detail on issue click here

whenever you will continuously browse www.google.com for 15 minutes in wpf web browser control then memory utilization of application keeps on increasing and it will never decrease, you can see increase in memory usage from task manager also.

please wait till 15 - 20 seconds after clicking inside the textbox, after 15-20 seconds onscreen keyboard will display.

Please help to avoid memory leak.

Thanks,

Pritesh

2 Answers2

0

This line of code is causing the memory leak, when I comment this code then memory leak stops.

#region  On screen keyboard
                        //Get the HTML of current page and cast as HTMLDocument
                        HTMLDocument document = (mshtml.HTMLDocument)webBrowser.Document;

                        //For each loop to access all the HTML tags in the current page
                        foreach (IHTMLElement links in document.all)
                        {
                            //If condition to access all the Input, Iframe and TextArea  in the current page and attach focus event to it
                            if (links.tagName.Contains("INPUT") || links.tagName.Contains("IFRAME") || links.tagName.Contains("TEXTAREA"))
                            {
                                HTMLInputTextElement textinput = links as HTMLInputTextElement;

                                if (textinput != null)
                                {
                                    HTMLInputTextElementEvents_Event handler = textinput as HTMLInputTextElementEvents_Event;

                                        if (handler != null)
                                        {
                                            handler.onfocus += new HTMLInputTextElementEvents_onfocusEventHandler(delegate()
                                            {
                                                IHTMLElement2 pwInput = null;
                                                pwInput = (IHTMLElement2)textinput;
                                                pwInput.focus();

                                                //This calls the LaunchOnScreenKeyboard() to show On screen keyboard on the screen when  Input, Iframe and TextArea tags are present in current page
                                                KeyboardManager.LaunchOnScreenKeyboard();
                                            });
                                        }
                                }
                            }
                        }
                        #endregion
  • Hi Gilad, i have use memory profiler, it is really good, it is also showing that above code is utilizing the more memory and not releasing memory, you can see the sample code by clicking on the link 'please find sample files here' in above issue description. – pritesh dabhi Jul 23 '15 at 12:28
0
  public static void LaunchOnScreenKeyboard()
        {
                try
                {
                    //This is used to get the osk.exe process and enable On screen keyboard
                    var processes = Process.GetProcessesByName("osk").ToArray();
                    if (processes.Any())
                        return;
                    var keyboardManagerPath = "osk.exe";
                        Process.Start(keyboardManagerPath);
                }
                catch (Exception ex)
                {

                }               
        }

This Method is also GetProcessesByName(processname)utilizing more memory