473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

C#-APP: Memory problem displaying context menu on notifyIcon

Hi

I have a problem with memory usage increasing when I right click to display the context menu on a notifyIcon

OS: Windows XP Professional SP2
Software: VS2005 Professional edition SP1

The steps to recreate my problem are as follows:

Start a new c# windows application
Add a notifyIcon
Add a contextMenuStrip
Type something into the context menu to create at least one menu item
Add an icon to the notifyIcon
Change the notifyIcon to use the contextMenuStrip
Run the application

Looking at task manager, the memory usage goes up every time the icon is right clicked.
If you do this for long enough all the available memory is used up, the program crashes, and all the memory is released.

Is this a known bug?
If so, is there a workaround?

I have also tried this in VB.NET and I get the same issue.

Any help would be appreciated.

Regards
Sep 19 '08 #1
2 2058
tlhintoq
3,525 Expert 2GB
Supplying the specific code sections would help a great deal.

But I could take a wild stab in the dark that when you create some object via the right-click of the notifyicon that you are not disposing of the object, thus it still resides in memory whether or not it has a visible representation on screen.
Sep 20 '08 #2
I did not supply code because I did not create any, using the steps I outlined above the following code was generated by Windows Form Designer:
Expand|Select|Wrap|Line Numbers
  1. namespace WindowsApplication1
  2. {
  3.     partial class Form1
  4.     {
  5.         /// <summary>
  6.         /// Required designer variable.
  7.         /// </summary>
  8.         private System.ComponentModel.IContainer components = null;
  9.  
  10.         /// <summary>
  11.         /// Clean up any resources being used.
  12.         /// </summary>
  13.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  14.         protected override void Dispose(bool disposing)
  15.         {
  16.             if (disposing && (components != null))
  17.             {
  18.                 components.Dispose();
  19.             }
  20.             base.Dispose(disposing);
  21.         }
  22.  
  23.         #region Windows Form Designer generated code
  24.  
  25.         /// <summary>
  26.         /// Required method for Designer support - do not modify
  27.         /// the contents of this method with the code editor.
  28.         /// </summary>
  29.         private void InitializeComponent()
  30.         {
  31.             this.components = new System.ComponentModel.Container();
  32.             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
  33.             this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
  34.             this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
  35.             this.helloToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  36.             this.contextMenuStrip1.SuspendLayout();
  37.             this.SuspendLayout();
  38.             // 
  39.             // notifyIcon1
  40.             // 
  41.             this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
  42.             this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
  43.             this.notifyIcon1.Text = "notifyIcon1";
  44.             this.notifyIcon1.Visible = true;
  45.             // 
  46.             // contextMenuStrip1
  47.             // 
  48.             this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  49.             this.helloToolStripMenuItem});
  50.             this.contextMenuStrip1.Name = "contextMenuStrip1";
  51.             this.contextMenuStrip1.Size = new System.Drawing.Size(109, 26);
  52.             // 
  53.             // helloToolStripMenuItem
  54.             // 
  55.             this.helloToolStripMenuItem.Name = "helloToolStripMenuItem";
  56.             this.helloToolStripMenuItem.Size = new System.Drawing.Size(108, 22);
  57.             this.helloToolStripMenuItem.Text = "Hello";
  58.             // 
  59.             // Form1
  60.             // 
  61.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  62.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  63.             this.ClientSize = new System.Drawing.Size(292, 266);
  64.             this.Name = "Form1";
  65.             this.Text = "Form1";
  66.             this.contextMenuStrip1.ResumeLayout(false);
  67.             this.ResumeLayout(false);
  68.  
  69.         }
  70.  
  71.         #endregion
  72.  
  73.         private System.Windows.Forms.NotifyIcon notifyIcon1;
  74.         private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
  75.         private System.Windows.Forms.ToolStripMenuItem helloToolStripMenuItem;
  76.     }
  77. }
I assume that there must be some problem with this code but I don't know what it is!
Do I need to generate this code manually, and if so how?
Sep 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Lalit | last post by:
Hi Friends, I have developed a Windows service. Now i need icon for this service in systray and context menu fo this icon. Can i do this? With regards, Lalit
0
by: A | last post by:
I know it doesn't work. But I'm really trying to figure out is when it might work. Does anyone from MSFT know? or perhaps anyone else in the ng know? I have an application that is entirely run...
2
by: Eric | last post by:
I implemented owner drawing on the main and context menus of my main form. It works fine. There is also a notify icon control that has a context menu. When the icon is in the status bar, it...
1
by: David | last post by:
Hi, I am developing a NotifyIcon app with C#. I want to show the context menu when user left-clicks on the icon, the same as he/she right-clicks on it. In that event handler,...
4
by: Claire | last post by:
Sorry Ive added this twice (sortof) but if I'd added an addendum to the first one then this would probably have been ignored. This problem affects a ContextMenu attached to a NotifyIcon object. I...
4
by: riggs | last post by:
Hi, I've got a simple program that contains a windows form with 3 command buttons on. The project also includes a notifyicon and a context menu. The context menu has 3 menu items (mirroring the 3...
0
by: Sakharam Phapale | last post by:
Hi All, I am using RichTextBox control for text editing purpose. If user selects some text and right clicks on RichTextBox then context menu is displayed. Now, problem is when user sets...
0
by: Neo | last post by:
I have created a Windows Service that shows a notifyicon in the system tray. I have also created a context menu for the notifyicon and implemented the notifyicons click event. The notifyicon...
0
by: Mike Eaton | last post by:
Hi there, I have an app whose structure is as follows: a module calls a custom application context containing a notify icon and associated context menu, which in turn acts upon an instance of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.