public SajatOsztaly()
 {
     NemmenedzseltMemoria = Marshal.AllocHGlobal(1000000);
     GC.AddMemoryPressure(1000000);
     for (int i = 0; i < 1000000; i++)
     {
         MenedzseltMemoria.Add(i);
     }
 }
Example #2
0
            public CrossBuffer(int width, int height)
            {
                int size = width * height * Marshal.SizeOf(typeof(Color32));

                intermediateBuffer = new byte[size];
                ManagedBuffer      = new Color32[width * height];
                NativeBuffer       = Marshal.AllocHGlobal(size);
                GC.AddMemoryPressure(size);
            }
 private void CommonInit(IInArchive archive, int filesCount, SevenZipExtractor extractor)
 {
     _archive    = archive;
     _filesCount = filesCount;
     _fakeStream = new FakeOutStreamWrapper();
     _fakeStream.BytesWritten += IntEventArgsHandler;
     _extractor = extractor;
     GC.AddMemoryPressure(MEMORY_PRESSURE);
 }
Example #4
0
 public BigNativeResource(int size)
 {
     m_size = size;
     if(m_size > 0)
     {
         GC.AddMemoryPressure(m_size);
     }
     Console.WriteLine("BigNativeResource create.");
 }
Example #5
0
        public static void AddMemoryPressure_InvalidBytesAllocated_ThrowsArgumentOutOfRangeException()
        {
            Assert.Throws <ArgumentOutOfRangeException>("bytesAllocated", () => GC.AddMemoryPressure(-1)); // Bytes allocated < 0

            if (s_is32Bits)
            {
                Assert.Throws <ArgumentOutOfRangeException>("pressure", () => GC.AddMemoryPressure((long)int.MaxValue + 1)); // Bytes allocated > int.MaxValue on 32 bit platforms
            }
        }
 public ReadOnlyRvMessage(Rv.Message msg, Uri source)
 {
     Contract.Requires(source != null);
     Contract.Requires(msg != null);
     _source   = source;
     _msg      = msg;
     _pressure = msg.Size;
     GC.AddMemoryPressure(_pressure); // RV does not add memory pressure, so we add it here so the CLR knows the underlying RV message contains unmanaged bytes
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ParticleBuffer" /> class.
        /// </summary>
        /// <param name="size"> The size. </param>
        public ParticleBuffer(int size)
        {
            _size = size;

            _nativePointer = Marshal.AllocHGlobal(SizeInBytes);
            _pointer       = (Particle *)_nativePointer;

            GC.AddMemoryPressure(SizeInBytes);
        }
Example #8
0
        public static Bitmap FromNativeResource(IntPtr handle, string resource)
        {
            if (string.IsNullOrEmpty(resource) || handle == IntPtr.Zero)
            {
                return(null);
            }

            Bitmap result;
            int    w = 0;
            int    h = 0;
            IntPtr ppvBits;
            IntPtr hBitmap = NativeMethods.LoadPNGResource(handle, resource, ref w, ref h, out ppvBits);

            if (hBitmap != IntPtr.Zero)
            {
                try
                {
#if PRESSURE
                    long pressure = InteropHelper.AlignToPage(w * h * 4);
                    if (pressure != 0L)
                    {
                        GC.AddMemoryPressure(pressure);
                    }
#endif

                    result = new Bitmap(w, h, PixelFormat.Format32bppArgb);
                    try
                    {
                        BitmapData data = result.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                        NativeMethods.RtlMoveMemory(data.Scan0, ppvBits, h * data.Stride); // copies the bitmap
                        result.UnlockBits(data);
                    }
                    catch (Exception ex)
                    {
                        TraceDebug.Trace("FromNativeResource: " + ex.Message + " Resource name " + resource);
                        result = null;
                    }
                }
                finally
                {
                    NativeMethods.DeleteObject(hBitmap);
#if PRESSURE
                    long pressure = InteropHelper.AlignToPage(w * h * 4);
                    if (pressure != 0L)
                    {
                        GC.RemoveMemoryPressure(pressure);
                    }
#endif
                }
                return(result);
            }
            else
            {
                return(null);
            }
        }
 public Job(int size)
 {
     if (size <= 0)
     {
         throw new ArgumentException("size need to be postive number");
     }
     _size = size;
     GC.AddMemoryPressure(_size);
     Console.WriteLine("The Job was created");
 }
Example #10
0
File: GC.cs Project: vein7/Net00
 public BigNativeResource(int size, int i)
 {
     this.size = size;
     this.i    = i;
     if (this.size > 0)
     {
         GC.AddMemoryPressure(this.size);
     }
     Console.WriteLine("BigNativeResource create " + i);
 }
Example #11
0
 public BigNativeResource(Int32 size)
 {
     m_size = size;
     // Пусть уборщик думает, что объект занимает больше памяти
     if (m_size > 0)
     {
         GC.AddMemoryPressure(m_size);
     }
     Console.WriteLine("BigNativeResource create.");
 }
Example #12
0
        private PixelMatrixContainer(int width, int height, int bytesPerPixels)
        {
            var stride = width * bytesPerPixels;

            _allocatedSize          = stride * height;
            _allocatedMemoryPointer = Marshal.AllocCoTaskMem(_allocatedSize);
            GC.AddMemoryPressure(_allocatedSize);

            FullPixels = new Pixel3Matrix(width, height, bytesPerPixels, stride, _allocatedMemoryPointer);
        }
Example #13
0
        internal SafeMILHandleMemoryPressure(long gcPressure)
        {
            _gcPressure = gcPressure;
            _refCount   = 0;


            // Removed WPF specific GC algorithm and all bitmap allocations/deallocations
            // are now tracked with GC.Add/RemoveMemoryPressure.
            GC.AddMemoryPressure(_gcPressure);
        }
Example #14
0
 public Job(string name)
 {
     _hJob = NativeJob.CreateJobObject(IntPtr.Zero, name);
     if (_hJob == IntPtr.Zero)
     {
         throw new InvalidOperationException();
     }
     GC.AddMemoryPressure(10485760);
     _processes = new List <Process>();
 }
Example #15
0
        /// <summary>
        /// Ensure that the GC knows the true cost of the object during collection.
        /// </summary>
        /// <remarks>
        /// If the object is actually bigger than the managed size reflects, it may
        /// be a candidate for quick(er) collection.
        /// </remarks>
        /// <param name="bytesAllocated">The amount of unmanaged memory that has been allocated.</param>
        private void AddMemoryPressure(long bytesAllocated)
        {
            if (bytesAllocated <= 0)
            {
                return;
            }

            GC.AddMemoryPressure(bytesAllocated);
            _memoryPressure += bytesAllocated;
        }
 private protected UnmanagedMemoryHandle(long size, bool zeroMem)
     : base(IntPtr.Zero, true)
 {
     handle = Marshal.AllocHGlobal(new IntPtr(size));
     GC.AddMemoryPressure(size);
     if (zeroMem)
     {
         Memory.ClearBits(handle, size);
     }
 }
Example #17
0
 private DiscordBot()
 {
     GC.KeepAlive(this);
     GC.SuppressFinalize(this);
     GC.AddMemoryPressure(24576);
     GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
     Configuration = new ConfigurationBuilder()
                     .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                     .Build();
 }
Example #18
0
        public ObjLinkToLargeResource(int size)
        {
            resourceSize = size;

            if (resourceSize > 100) //greater than a threshold
            {
                GC.AddMemoryPressure(resourceSize);
            }
            Console.WriteLine("Create obj with resource size " + resourceSize.ToString());
        }
Example #19
0
 /// <summary>
 /// Prepare Memory for large allocation before doing it
 /// Could check if memory wanted is present before doing it and should be used before call with hasenoughmemory
 /// </summary>
 public void PrepareLargeOperation()
 {
     try
     {
         GC.AddMemoryPressure(5000000);
     }
     catch
     {
     }
 }
Example #20
0
        public static UnmanagedImage Create(int width, int height, PixelFormat pixelFormat)
        {
            int num = 0;

            switch (pixelFormat)
            {
            case PixelFormat.Format8bppIndexed:
                num = 1;
                break;

            case PixelFormat.Format16bppGrayScale:
                num = 2;
                break;

            case PixelFormat.Format24bppRgb:
                num = 3;
                break;

            case PixelFormat.Format32bppRgb:
            case PixelFormat.Format32bppPArgb:
            case PixelFormat.Format32bppArgb:
                num = 4;
                break;

            case PixelFormat.Format48bppRgb:
                num = 6;
                break;

            case PixelFormat.Format64bppPArgb:
            case PixelFormat.Format64bppArgb:
                num = 8;
                break;

            default:
                throw new UnsupportedImageFormatException("Can not create image with specified pixel format.");
            }
            if (width <= 0 || height <= 0)
            {
                throw new InvalidImagePropertiesException("Invalid image size specified.");
            }
            int num2 = width * num;

            if (num2 % 4 != 0)
            {
                num2 += 4 - num2 % 4;
            }
            IntPtr dst = Marshal.AllocHGlobal(num2 * height);

            SystemTools.SetUnmanagedMemory(dst, 0, num2 * height);
            GC.AddMemoryPressure(num2 * height);
            UnmanagedImage unmanagedImage = new UnmanagedImage(dst, width, height, num2, pixelFormat);

            unmanagedImage.mustBeDisposed = true;
            return(unmanagedImage);
        }
        public static async Task RunMemoryLeakAsync()
        {
            var connectionFactory = await CreateChannelFactoryAsync().ConfigureAwait(false);

            var connection = await CreateConnection(connectionFactory).ConfigureAwait(false);

            Parallel.For(0, 100, async(i) =>
            {
                var channel = await CreateChannel(connection).ConfigureAwait(false);
                ChannelSequences.Add(channel, channel.NextPublishSeqNo);

                await SendMessageAsync(channel, i).ConfigureAwait(false);

                var result = await ReceiveMessageAsync(channel).ConfigureAwait(false);
                await Console.Out.WriteLineAsync(Encoding.UTF8.GetString(result.Body)).ConfigureAwait(false);
                await Console.Out.WriteLineAsync($"Iteration {i} ChannelSequences Count: {ChannelSequences.Count}").ConfigureAwait(false);

                channel.Dispose();
                i++;
            });

            foreach (var kvp in ChannelSequences)
            {
                await Console.Out.WriteLineAsync($"WTF AM I: {kvp.Key.GetType()} AND WHAT DO I HOLD: {kvp.Key}").ConfigureAwait(false);
            }

            for (int i = 0; i < ChannelSequences.Count; i++)
            {
                try
                {
                    var channel = ChannelSequences.ElementAt(i).Key;
                    await SendMessageAsync(channel, i + 1000).ConfigureAwait(false);
                }
                catch (RabbitMQ.Client.Exceptions.AlreadyClosedException ace)
                {
                    await Console.Out.WriteLineAsync($"AlreadyClosedException #{i.ToString("000")} Reason: {ace.ShutdownReason}").ConfigureAwait(false);
                }
            }

            for (int i = 0; i < 5; i++)
            {
                await Console.Out.WriteLineAsync($"Iteration {i} ChannelSequences Count {ChannelSequences.Count}").ConfigureAwait(false);

                await Console.Out.WriteLineAsync($"Memory in KBytes of Application {(GC.GetTotalMemory(false) - TotalMemoryInBytesAtStart) / 1000.0}").ConfigureAwait(false);

                Thread.Sleep(10000);
                GC.AddMemoryPressure(Environment.SystemPageSize);
                GC.Collect();
            }

            foreach (var kvp in ChannelSequences)
            {
                await Console.Out.WriteLineAsync($"WTF AM I: {kvp.Key.GetType()} AND WHAT DO I HOLD: {kvp.Key}").ConfigureAwait(false);
            }
        }
Example #22
0
 private void SetMemoryPressure()
 {
     try
     {
         GC.AddMemoryPressure(_sizeInByte);
     }
     catch (ArgumentOutOfRangeException ex)
     {
         Trace.TraceWarning(ex.Message);
     }
 }
Example #23
0
        /// <summary>
        /// Creates a contacts record list.
        /// </summary>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
        /// <since_tizen> 4 </since_tizen>
        public ContactsList()
        {
            int error = Interop.List.ContactsListCreate(out _listHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "ContactsList Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            GC.AddMemoryPressure(_memoryPressure);
        }
Example #24
0
 public Job(string name, long sizeInByte)
 {
     if (sizeInByte < 1)
     {
         throw new ArgumentOutOfRangeException("Size", "Size must be greater than 0");
     }
     _size = sizeInByte;
     _name = name;
     GC.AddMemoryPressure(_size);
     Console.WriteLine($"{_name} was created", _name);
 }
Example #25
0
        public UnmanagedImage Clone()
        {
            IntPtr dst = Marshal.AllocHGlobal(stride * height);

            GC.AddMemoryPressure(stride * height);
            UnmanagedImage unmanagedImage = new UnmanagedImage(dst, width, height, stride, pixelFormat);

            unmanagedImage.mustBeDisposed = true;
            SystemTools.CopyUnmanagedMemory(dst, imageData, stride * height);
            return(unmanagedImage);
        }
Example #26
0
 public Tile(byte[] data, int width, int height, bool digable)
 {
     this._data    = data;
     this._width   = width;
     this._height  = height;
     this._digable = digable;
     this._bw      = this._width / 8 + 1;
     this._bh      = this._height;
     this._rect    = new Rectangle(0, 0, this._width, this._height);
     GC.AddMemoryPressure((long)data.Length);
 }
Example #27
0
 public Job(string name, int memorySize)
 {
     if (memorySize < 1)
     {
         throw new InvalidOperationException("Invalid memory size - Job not created!");
     }
     InitJob(name);
     this.memorySize = memorySize;
     GC.AddMemoryPressure(memorySize);
     Console.WriteLine($"Created job with {memorySize} memory bytes");
 }
Example #28
0
 public static void AddMemoryPressure(long bytesAllocated)
 {
     if (bytesAllocated < 0L)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (bytesAllocated > 0L)
     {
         GC.AddMemoryPressure(bytesAllocated);
     }
 }
Example #29
0
            public UnmanagedBlob(StandardRuntimePlatform plat, int size)
            {
                _plat   = plat;
                Address = plat.Alloc(size);
                GC.AddMemoryPressure(size);
                Size = size;
#if DEBUG
                _backtrace = Environment.StackTrace;
                Backtraces.Add(_backtrace);
#endif
            }
Example #30
0
        /// <summary>
        /// Creates a calendar list.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/calendar</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
        public CalendarList()
        {
            int error = Interop.List.Create(out _listHandle);

            if (CalendarError.None != (CalendarError)error)
            {
                Log.Error(Globals.LogTag, "CalendarList Failed with error " + error);
                throw CalendarErrorFactory.GetException(error);
            }
            GC.AddMemoryPressure(_memoryPressure);
        }