Testing MemoryUseLevel

Wanting to see how Sansar's scripting engine "feels" about memory usage, I ran a simple program to probe its thresholds. The MemoryUseLevel enumeration has a few abstract options: Low (no problem), Warning, Critical, and Limit.

The number I'm reporting reflects the large arrays of bytes summed up and ignores overhead for the List<byte[]> data structure and the program as loaded into memory.

I get inconsistent results in my tests. I think there is a subsystem that periodically keeps an eye on the scene and pushes out these warnings. So take these results with a grain of salt.

Whether and when I get to Warning or Critical varies from test to test, so it's not worth giving numbers here. It does seem that I consistently hit Limit (maximum) around the 10 MB mark. Sometimes before, sometimes after.

I continued running the script well past 100 MB and saw no ill effects.


I conclude that they consider 10 MB to be the limit of how much memory they want you to allocate to a single script. One way you can use this is to add a subscription to your own scripts to the memory alerts and broadcast a warning somehow when you hit the Limit value. In the future they may clamp down on scripts that go over 10 MB by terminating them, throttling their performance, warning users, or some other sanction.


You can run this test, too. Below is my source code. Once loaded, you can use the "start", "stop" and "step" commands to walk slowly through the memory increases. You can also use the "reset" command, which uses a "restricted" feature to restart the scene that may be taken away in the future.

using System;
using Sansar.Script;
using Sansar.Simulation;
using System.Collections.Generic;

public class TestScript : SceneObjectScript {

private MemoryUseLevel MemoryWarning = MemoryUseLevel.Low;
private int ChunkSize = 1048576 / 4; // 1/4 MB
private long GlutSize = 0;
private List<byte[]> Glut = new List<byte[]>();

public override void Init() {
ScenePrivate.Chat.Subscribe(0, null, ChatMessage);
Memory.Subscribe((tracking, UseLevel) => { MemoryWarning = UseLevel; });

private void Update() {
Glut.Add(new byte[ChunkSize]);
GlutSize += ChunkSize;
ScenePrivate.Chat.MessageAllUsers(MemoryWarning.ToString() + " -> " + ((float) GlutSize / 1048576).ToString("#,##0.## MB"));

private void ChatMessage(int Channel, string Source, SessionId SourceId, ScriptId SourceScriptId, string Message) {

if (Message == "reset") {

} else if (Message == "start") {

} else if (Message == "stop") {

} else if (Message == "step") {






Please sign in to leave a comment.