Widgets – Cancel That

I take back what I said about the Yahoo! Widgets Engine. It doesn’t support garbage collection on graphics objects and doesn’t seem to clean up it’s resources worth a damn leading to some pretty serious memory issues. A little program like the one below will chew through memory like it was going out of style. I should not have to delete anything, that’s rediculous. Objects should be destroyed when they fall out of scope. Yuck.

UPDATE I’ve also noticed that setting fonts on a particular object will run GDI resources up. This is horrible. If you reset a font face on a graphics object, it apparently recreates the font drawing resouces without destroying the old resources. So to keep these things from dragging a system down and ultimately crashing, you have to reuse graphics objects like Text and TextArea, and you can’t reset properties like text.font = “Arial”. Pretty sloppy system IMHO.

<?xml version='1.0' encoding='utf-8'?>
<?konfabulator xml-strict='true'?>
<widget version='1.0' minimumVersion='3.0'>
  <debug>on</debug>
  <window title='TestCases'>
    <name>MainWindow</name>
    <width>200</width>
    <height>600</height>
    <visible>0</visible>
    <shadow>1</shadow>
    <frame name='MainFrame' visible='true'>
      <vOffset>0</vOffset>
      <hOffset>0</hOffset>
      <height>200</height>
      <width>600</width>
    </frame>
  </window>
  <action trigger='onLoad'>
    <![CDATA[

var g_vOffset = 0;

function timerTick()
{
  if ( MainFrame.subviews != undefined )
  {
    delete MainFrame.subviews[0].subviews[0].removeFromSuperView(); // text area
    delete MainFrame.subviews[0].removeFromSuperView(); // frame
  }
  
  var frame = new Frame();
  var text = new TextArea();

  text.color      = '#000000';
  text.size       = 30;
  text.editable   = false;
  text.scrollbar  = false;
  text.vOffset    = g_vOffset;
  text.hOffset    = 0;
  text.width      = 200;
  text.font       = 'Helvetica';
  text.data       = 'Some Text';

  g_vOffset += 1;

  frame.addSubview( text );

  MainFrame.addSubview( frame );
}
MainWindow.visible = true;

]]>
  </action>
  <timer name='mainTimer'>
    <interval>.1</interval>
    <ticking>true</ticking>
    <onTimerFired>
    <![CDATA[
    timerTick();
    ]]>
    </onTimerFired>
  </timer>
</widget>

Leave a Reply

Your email address will not be published. Required fields are marked *