2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . Linq ;
5
+ using System . Threading ;
5
6
using System . Threading . Tasks ;
6
7
using Microsoft . AspNetCore . Mvc ;
7
8
using Microsoft . Extensions . Logging ;
@@ -11,7 +12,6 @@ namespace SignalRMonitor.Controllers
11
12
{
12
13
public class HomeController : Controller
13
14
{
14
- private static List < byte [ ] > MemoryMonster = new List < byte [ ] > ( ) ;
15
15
private readonly ILogger < HomeController > _logger ;
16
16
17
17
public HomeController ( ILogger < HomeController > logger )
@@ -32,7 +32,6 @@ public IActionResult Privacy()
32
32
[ HttpPost ( "/cpu" ) ]
33
33
public async Task < IActionResult > UseCPU ( )
34
34
{
35
- Console . WriteLine ( "c" ) ;
36
35
var timeout = DateTime . Now . AddSeconds ( 5 ) ;
37
36
while ( DateTime . Now . CompareTo ( timeout ) < 0 )
38
37
{
@@ -42,19 +41,19 @@ public async Task<IActionResult> UseCPU()
42
41
return Ok ( ) ;
43
42
}
44
43
[ HttpPost ( "/ram" ) ]
45
- public async Task < IActionResult > UseRAM ( )
44
+ public void UseRAM ( )
46
45
{
47
46
byte [ ] buff = new byte [ 1024 * 1024 * 1024 ] ;
48
- for ( var i = 0 ; i < buff . Length ; i ++ ) buff [ i ] = ( byte ) ( i % 256 ) ;
49
- MemoryMonster . Add ( buff ) ;
47
+ for ( var i = 0 ; i < buff . Length ; i ++ ) buff [ i ] = ( byte ) ( i ) ;
50
48
//Sleep 5 seconds to keep the memory space "active"
51
- await Task . Delay ( 5000 ) ;
49
+ Thread . Sleep ( 5000 ) ;
52
50
//release memory
53
- MemoryMonster = new List < byte [ ] > ( ) ;
54
- return Ok ( ) ;
51
+ buff = null ;
52
+ GC . Collect ( ) ;
53
+ GC . WaitForPendingFinalizers ( ) ;
54
+ GC . Collect ( ) ;
55
55
}
56
56
57
-
58
57
[ ResponseCache ( Duration = 0 , Location = ResponseCacheLocation . None , NoStore = true ) ]
59
58
public IActionResult Error ( )
60
59
{
0 commit comments