dlaczego zapycha pamiec ??

0

witam

napisalem sobie taki maly programik ktory odczytuje wartosc z pamieci
i przekazuje ja do innego mojego programu
problem jest w tym ze stopniowo zapycha mi pamiec operacyjna

jest np uzyte 200MB a po kilku godzinach jest 700MB
wylaczam znowu spoada do 200MB
wlaczam i powoli znowu rosnie ??
gdzie popelnilem blad :)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Timers;
using System.Globalization;

namespace Read_Adres
{
    public partial class Form1 : Form
    {
        private delegate void AppendTextHandler();
        public class Mt4
        {
            [DllImport("MMF_MT4.dll")]
            public static extern int MMF_Init(string AShareName, int AMaxSize);
            [DllImport("MMF_MT4.dll")]
            public static extern bool MMF_WriteDouble(int AHandle, double AValue);
            [DllImport("MMF_MT4.dll")]
            public static extern bool MMF_WriteInt(int AHandle, int AValue);
        }
        public class WinApi
        {
            [DllImport("kernel32.dll")]
            public static extern int OpenProcess(UInt32 DesiredAccess, Boolean InheritHandle, int PID);
            [DllImport("kernel32.dll")]
            public static extern Int32 ReadProcessMemory(int Process, int BaseAddress,
                [In, Out] byte[] buffer, UInt32 size, out int NumberOfBytesRead);
        }
        // uruchomienie timera
        private void start()
        {
            System.Timers.Timer licznik = new System.Timers.Timer();
            licznik.Elapsed += new ElapsedEventHandler(czas);
            licznik.Interval = 100;
            licznik.Enabled = true;
        }
        // wykonanie czynnosci w timerze
        private void czas(object source, ElapsedEventArgs e)
        {
            if (enabled == true) i1();

        }
        public Form1()
        {
            InitializeComponent();
            start();
        }
        // button
        bool enabled;
        int handlebid;
        int handlecon;
        private void button1_Click(object sender, EventArgs e)
        {
            if (enabled == false) enabled = true; else enabled = false;
            handlebid = Mt4.MMF_Init(Comment.Text + "bid", 16);
            handlecon = Mt4.MMF_Init(Comment.Text + "con", 16);
            if (enabled == false)
            {
                Comment.Enabled = true;
                Pid.Enabled = true;
                Adres.Enabled = true;
                Mt4.MMF_WriteInt(handlecon, 0);
            }
            else
            {
                Comment.Enabled = false;
                Pid.Enabled = false;
                Adres.Enabled = false;
                Mt4.MMF_WriteInt(handlecon, 1);
            }
        }
        // odczyt i zapis do pamieci wspoldzielonej
        int processID = 0;
        private void i1()
        {
            if (Adres.InvokeRequired)
                Adres.Invoke(new AppendTextHandler(i1));
            else
            {
                if (Pid.Text.Length > 0 && Adres.Text.Length > 0)
                {
                    byte[] buffor = new byte[255];
                    int NBR = 0;
                    int adres = System.Convert.ToInt32(Adres.Text, 16);
                    if (processID == 0) processID = WinApi.OpenProcess(0xFFF, false, System.Convert.ToInt32(Pid.Text));
                    WinApi.ReadProcessMemory(processID, adres, buffor, 100, out NBR);
                    System.Text.Encoding enc = System.Text.Encoding.Unicode;
                    string myString = enc.GetString(buffor);
                    myString = myString.Substring(Convert.ToInt16(Digits1.Value),Convert.ToInt16(Digits2.Value));
                    double bid;
                    bid = Double.Parse(myString, CultureInfo.InvariantCulture);
                    button1.Text = bid.ToString();
                    Mt4.MMF_WriteDouble(handlebid, bid);
                    
                }
            }
        }
    }
}

pzdr Andrzej

0

a CloseHandle ?!

1 użytkowników online, w tym zalogowanych: 0, gości: 1