2
Answers

memmory problem

Ask a question
george

george

15y
2.4k
1

im my project the memmory usage begines with 9200k and goes to 150000Mb!!

why?

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO.Ports;

 

 

 

using System.Text.RegularExpressions;

 

namespace SimpleSerial

{

public partial class Form1 : Form

{

// Add this variable

string RxString;

public string displine1;

public string displine2;

public Form1()

{

InitializeComponent();

serialPort1.PortName = "COM5";

serialPort1.BaudRate = 19200;

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //eksafanizei ta pano button tis formas

//this.TopMost = true; //me true always on top i forma

//WindowState = FormWindowState.Maximized; //i forma na einai form maximize

//orizoume syntetagmenes tou position

int monitorHeight;

int monitorWidth;

int monitorcenterHeight;

int monitorcenterWidth;

int formposition;

monitorHeight = SystemInformation.PrimaryMonitorSize.Height; //pernoume stin metavliti monitorHeight to Height tis trexousas analisis tis othonis

monitorWidth = SystemInformation.PrimaryMonitorSize.Width; //pernoume stin metavliti monitorWidth to Width tis trexousas analisis tis othonis

monitorcenterHeight = monitorHeight / 2; // to dieroume /2 gia na broume to kentro

monitorcenterWidth = monitorWidth / 2;

formposition = monitorWidth - 390;

this.StartPosition = FormStartPosition.Manual; //energopioume manual position

this.Location = new Point(formposition, 0);

textBox1.SelectionStart = 0;

textBox1.SelectionLength = 0;

 

if (!CheckIfPortExists(serialPort1.PortName))

{

MessageBox.Show(serialPort1.PortName + " doesn't exist on this computer");

Close();

}

else

{

try

{

serialPort1.Open();

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

//MessageBox.Show("Serial port in use");

}

}

}

 

 

private bool CheckIfPortExists(string portName)

{

foreach (string name in SerialPort.GetPortNames())

{

if (name == portName) return true;

}

return false;

}

private void DisplayText(object sender, EventArgs e)

{

foreach (string strItem in Regex.Split(RxString, "#2#"))

{

displine1 = strItem;

}

 

textBox1.Text = displine1;

}

 

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

{

System.GC.Collect(); //meionei tin mnimi kai kanei suspent to thread

System.GC.WaitForPendingFinalizers();

////RxString = serialPort1.ReadExisting();

RxString = serialPort1.ReadLine();

//meionei tin mnimi kai kanei suspent to thread

this.Invoke(new EventHandler(DisplayText));

}

}

}

 


Answers (2)
Next Recommended Forum