By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

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

P: 2
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
Share this Question
Share on Google+
2 Replies


tlhintoq
Expert 2.5K+
P: 3,525
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

P: 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

Post your reply

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