PDA

View Full Version : ازاد سازی فضای اختصاص داده شده



sevenboys
سه شنبه 17 اردیبهشت 1392, 11:02 صبح
چگونه در سی شارپ یک ارایه را پاک کنم و مقدار فضای که به آن اختصاص داده شده را ازاد نمایم؟

tooraj_azizi_1035
سه شنبه 17 اردیبهشت 1392, 11:21 صبح
using System;

class MyGCCollectClass
{
private const int maxGarbage = 1000;

static void Main()
{
// Put some objects in memory.
MyGCCollectClass.MakeSomeGarbage();
Console.WriteLine("Memory used before collection: {0:N0}",
GC.GetTotalMemory(false));

// Collect all generations of memory.
GC.Collect();
Console.WriteLine("Memory used after full collection: {0:N0}",
GC.GetTotalMemory(true));
}

static void MakeSomeGarbage()
{
Version vt;

// Create objects and release them to fill up memory with unused objects.
for(int i = 0; i < maxGarbage; i++) {
vt = new Version();
}
}
}
// The output from the example resembles the following:
// Memory used before collection: 79,392
// Memory used after full collection: 52,640

omidaminiazar
سه شنبه 17 اردیبهشت 1392, 13:55 عصر
می توانی آرایه را در یک کلاس تعریف کنی و از آن استفاه کنی و اگه کارت با آن تمام شد با یک متد مخرب تمام فضای اشغالی توسط کلاس گرفته شده همراه با ارایه را حذف کنی
این یک پیشنهاد است

sevenboys
سه شنبه 07 خرداد 1392, 16:27 عصر
میشه یه کم در مورد این کد توضیح دهید؟؟(من یک ارایه دارم که توی حلقه تعریف کرده ام و میخواهم در هر بار اجرای حلقه ارایه قبلی فضای را که گرفته رها سازی کند چون اگه رها سازی نکند تمام حلقه اجرا نمیشود)


using System;

class MyGCCollectClass
{
private const int maxGarbage = 1000;

static void Main()
{
// Put some objects in memory.
MyGCCollectClass.MakeSomeGarbage();
Console.WriteLine("Memory used before collection: {0:N0}",
GC.GetTotalMemory(false));

// Collect all generations of memory.
GC.Collect();
Console.WriteLine("Memory used after full collection: {0:N0}",
GC.GetTotalMemory(true));
}

static void MakeSomeGarbage()
{
Version vt;

// Create objects and release them to fill up memory with unused objects.
for(int i = 0; i < maxGarbage; i++) {
vt = new Version();
}
}
}
// The output from the example resembles the following:
// Memory used before collection: 79,392
// Memory used after full collection: 52,640

tooraj_azizi_1035
سه شنبه 07 خرداد 1392, 16:29 عصر
کدتو بذار.

FastCode
سه شنبه 07 خرداد 1392, 18:37 عصر
این خیلی عالیه:
http://www.infoq.com/presentations/justin-smith-clr-gc
پیشنهاد میکنم حتما ببینی