You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an app that generates cards for a boardgame. The text varies a lot, so I set the fontsize dynamically, in a do/while loop, where I check if the textBox is Truncated or not. here's a simple example:
RichString textBox = null;
var fontSize = 1000;
do
{
fontSize--;
textBox = new RichString
{
MaxHeight = 512,
MaxWidth = 512
};
textBox.Add("test test test test test", fontSize: fontSize);
} while (textBox.Truncated);
The issue is, if the while loop runs a lot, the memory consumption of my app skyrockets. Here's an example snapshot:
As you can see, there are more then 16 million StyleManagers, and there's a huge Dictionary<string, Topten.RichTextKit.Style>.
I'm not sure if it's a bug, or I misuse it. Can you have a look at it?
The text was updated successfully, but these errors were encountered:
I'm not sure how you're getting 16M styles - unless you're actually using 16M different style combinations?
To be clear, in your example, you could be creating up to 1,000 styles the first time you run through that code. The second time though those same 1,000 styles should be re-used. See here for the code that checks the style cache for existing values.
When I tried your code, the first time through it did create a lot of styles, but when I ran the same code again, the previously created styles were re-used. Perhaps set a breakpoint on the line linked above and see if you can see why it's creating so many styles.
btw: This would much faster (about 50x) if you used a binary search. eg: this code finds the same answer as yours with 11 attempts (instead of 800+). It will use less memory too.
varmin=1;varmax=1000;while(max-min>1){varmid=(min+max)/2;textBox=newRichString{MaxHeight=512,MaxWidth=512};textBox.Add("test test test test test",fontSize:mid);if(textBox.Truncated)max=mid;elsemin=mid;}```
Hi,
I have an app that generates cards for a boardgame. The text varies a lot, so I set the fontsize dynamically, in a do/while loop, where I check if the textBox is Truncated or not. here's a simple example:
The issue is, if the while loop runs a lot, the memory consumption of my app skyrockets. Here's an example snapshot:
As you can see, there are more then 16 million StyleManagers, and there's a huge Dictionary<string, Topten.RichTextKit.Style>.
I'm not sure if it's a bug, or I misuse it. Can you have a look at it?
The text was updated successfully, but these errors were encountered: