Wednesday, March 30, 2011

Memory Management in REALbasic

Many times we see the question asked "when does REALbasic's garbage collector run" or something to this effect.

REAlbasic does NOT use a garbage collector like Java's VM does.(see Garbage collection on wikipedia) It uses reference counting (also mentioned on this same wikipedia page) and when the reference count drops to 0 the object is destroyed immediately. Not some time later but right then and there.

Note that this has certain implications. If you have circular references where one object has a reference to another and that object has a reference back to the first then the reference counts may never drop to zero. And, if for some reason you lose your original references to these objects then you can "leak" - or have objects that will never be destroyed but that you can no longer access or reference (well not easily at least).

There are some excellent resources that cover this in plain language and that give you some excellent tips on how to avoid common pitfalls.

The recent Atlanta conference had a session on Advanced Language features and Charles Yeomans covered this fairly well in his talk. I'd suggest that you find the video from this session when they are available on the ARBP site.

Tuesday, March 29, 2011

Web Edition Updates

Today we're introducing a new update mechanism for Web Edition that allows us to provide patches to the Web Framework without having to release a whole new version of the IDE.

It works like this:

1. Download a PageSource object from the Extras section of the Downloads page.
2. Drag it into the project that needs the bug fix.
3. Add it to any pages that need the bug fix.

If we release another Web Edition Update, you can just delete the old class from your project and add the new one. All of the subclasses on each page will automatically be updated.

When the next major version of the Real Studio IDE is released, all of this code will be included in the Web Edition framework and the patches are automatically disabled.

Today's update includes two bug fixes:

1. GotFocus and LostFocus events have been fixed for Firefox
2. Touch events have been greatly improved for iOS devices
3. Fixed a bug in WebPopupMenu where changing the menu using the List(index) method caused a Javascript error.

The file is available in the Extras section of our Downloads page or you can download it directly by clicking here.

Friday, March 25, 2011

The Real Studio Atlanta Summit

This past weekend was the Real Studio Atlanta Summit hosted by the Association of Realbasic Professionals. Four of us from Real Software, Thom, Greg, Norman and myself attended, and Thom and I presented sessions. The conference lasted two days with lots of sessions aimed at various levels of Real Studio proficiency.

Getting so many Real Studio users together in one place is always a great thing. Those of us at Real Software who attended really enjoyed talking to long-time users and meeting new ones as well. The speakers all did a great job. The wide range of experiences both speakers and attendees had was amazing.

I'm sure there will be Real Studio conferences in the future and I highly recommend attending. You will learn from the sessions and the hallway conversation with other users, as well as gain valuable networking opportunities. It's a lot of fun too!

Thursday, March 24, 2011

Attack of the Clones

For a long time now (perhaps since the very beginning) the Realbasic framework has allowed you to have a menu item appear in multiple locations. For example, you might have a menu that appears in your menubar but also appears in a contextual menu somewhere else in your project. In order for the Realbasic framework to allow this, the entire menubar is rebuilt every time you open it or type a keyboard shortcut.

This has led to problems in the past. For example, plug-ins cannot modify menus nor can declares. These limitations have been around for quite some time and we have all grown accustomed to them, even if we prefer they didn't exist. It also has a considerable runtime cost to continually rebuild the menubar during typing. In our transition to Cocoa we would like to take the opportunity to move to a system where the menubar is stable and does not have to be dynamically updated.

While the end result is much nicer, there is a downside: backwards compatibility. If you are using a menu item object in multiple locations once we make this change your code will break. Specifically, it will raise a MenuHasParentException.

Fortunately, updating your code will be pretty straightforward. Rather than having the menu item be in two or more places at once, you will instead clone the menu item using the newly added Clone() method.

To make this transition less painful, this behavior will be required only for the Cocoa framework starting with Real Studio 2011 R2. All desktop frameworks (Mac OS X Carbon, Windows and Linux) will support it but the others will initially continue to support the old behavior as well. Beginning with Real Studio 2011 R4 it will be required for all desktop frameworks so that there is a single, standard technique (cloning) for dealing with menu items that appears in multiple
locations.

We don't make changes that will break code without a lot of thought. But a little bit of pain now will save a lot of it down the road. It's really better that we allow the OS to handle as much as possible so that when OS changes occur, they have minimal impact on your projects. And in this case, you will even gain some functionality because plugins and declares will be able to modify menus.

If you are not using menu items in multiple locations, this will have no impact on you. If you are, I think you can see that the gain will be well worth the effort.

Wednesday, March 23, 2011

Using links in your comments

Ever find that you had to read a set of online documentation or specifications in order to implement something and thought it would be really nice to put a reference to that material in your code just in case you or someone who maintained the code might need it later?

One handy feature in the IDE is that if you put a full URL in a comment the IDE will actually recognize it as a URL and highlight it so it's clickable.

And it works with several URL schemes
In a code editor, if you put in code like:

// this came from code at http://developer.apple.com/

the URL for developer.apple.com highlights and appears as a clickable URL

Or you can use mailto if you've sent source code to others so they can easily mail you back

// mailto:blah@example.com

And yes, you can add subject lines as follows:

// mailto:blah@example.com?subject=Hey%20there

If you click on a mailto link, like above that is in your RB code, it starts your email client & addresses it to "blah@example.com" with a subject if you had one.

This is really handy when you need to refer to documentation from Apple, GTK, MSDN, etc. so you or the person who comes along later can see where you got the reference material from.

Tuesday, March 22, 2011

Plugging IDE Memory Leaks

During the development of Real Studio 2011r1, we spent some time analyzing the compiler's memory usage. What we noticed was that the compiler was leaking memory. A memory leak occurs when code uses memory but then does not release this memory when it’s finished with it. The result is that the amount of memory the application uses continues to increase until the user quits the application or the application uses up all available memory and crashes.

During the development of 2011r1 we fixed every memory leak in the compiler. In fact, we went beyond that and fixed every leak we could find in the IDE. We fixed leaks in some framework classes as well such as:
  • Shell
  • RealSQLDatabase
  • TabPanel
  • VirtualVolumes
  • PopupMenus
  • MemoryBlocks

As you may know, the Real Studio IDE is created with Real Studio and the Realbasic language. We create it in the same way you create your projects. The chart below compares running the Real Studio IDE project in 2010r5.1 (blue) versus 2011r1(green). All tests were performed by running the project in the debugger and then closing the project. Incremental compilation was disabled.


You can see that after five runs of the project, Real Studio 2010r5.1 leaked over 45 megabytes of memory. Compare that to Real Studio 2011r1 (green) where after five runs, not a single extra byte of memory was leaked.

This is a huge improvement in the performance of the IDE. Before 2011r1, if you were using the IDE for long periods of time, you probably found that it would slow down to the point where you had to restart it. By doing this you were releasing the memory that had not been released by the IDE. This is no longer an issue in 2011r1 which means you can now run the IDE for very long periods of time without having to restart due to memory leaks.

While we believe we have found every leak in the IDE, it is possible there are others and there are certainly leaks that remain in some framework classes. Should you believe you have found a memory leak, create a simple sample project and include it with a new case in our Feedback system.

Thursday, March 17, 2011

5% of Next Week's Sales will be Donated to Japan’s Relief Efforts

Real Software will donate 5% of our total sales for the week of March 20-26 to the American Red Cross’ earthquake and tsunami relief fund for Japan. All products including new Real Studio licenses, renewals, upgrades and support plans will be applicable.  This is one small way we can help our friends in Japan after this devastating disaster.

Wednesday, March 16, 2011

I want my iPadTV!

When my daughter was eight, she started asking if she could have a computer in her room. When she turned nine, I decided that an iPad would be a nice compromise and she loves it. She's about to turn 10 years old and lately has been asking if she can have a TV in her room. That's not going to happen.

Yesterday, Time Warner Cable released a free application for the iPad that lets TWC customers watch 30 channels of TV on the iPad. It's a very nice app that works very well. I was happy to see that at least for the moment, the Disney Channel is not among the available iPad channels. However, Food Network is and my daughter loves that. So it looks like she's going to get a TV in her room (and in fact, anywhere in the house she takes her iPad) after all. You might think that watching TV on a iPad-sized screen wouldn't be all that great. But considering that you quite literally watch TV at an arm's length on the iPad, the viewing size actually works very well. Rather than spend money on another TV, you can now just use your iPad.

This was a very smart move on the part of Time Warner Cable. People are spending more and more time in front of their iPads (and computers) and less and less time watching TV. So what they have done is put themselves in front of those iPad users with an app. It will likely increase viewing and give their customers another reason to keep their cable and internet service with TWC.

It's great for Apple as well because at least some people will decide to spend their money on an iPad instead of buying yet another TV. Why buy a TV when you can have an iPad that does so much more for about the same price?

This is yet another sign of how important the iPad (and tablets in general) will be to the future of computing. We are committed to supporting these and are working on the prerequisite steps needed to do so. The most important of those is completing our support for LLVM. We already have support for LLVM in RBScript. Next, we need to support it for stand-alone applications. Once this is done, we will have the ARM processor support we need to begin building an iOS framework and possibly support other mobile devices.

Mobile devices are going to be critical to the future of computing and to the future of Real Studio.

Wednesday, March 9, 2011

Using Mac OS X tools to manipulate the Info.Plist

There are several tools and ways to edit the property list, or plist, that's part of every Mac OS X bundle.

You might need to do this as part of getting your application ready for the Mac Application Store or because your application requires a newer version of Mac OS X than the default required by most Real Studio applications. Real Studio will, by default, set the entry for LSMinimumSystemVersion to 10.4 for Carbon apps or 10.5 for Cocoa applications.

If you have the Apple developer tools installed you can, as part of any build or run, use the Property List Editor in Developer > Applications > Utilities > Property List Editor to edit your plist. This is a nice GUI tool that Apple supplies that makes editing an applications plist very easy.
You can use this tool whether you are debugging or not by making use of Run Paused.
When you use Run Paused you can then locate the application, open the bundle and use the Apple Property List Editor to change/update whatever you need and then, when done, run the debug application and it will connect to the IDE that is waiting.

If you have an edition that supports Build Automation, you could script the change as a post build step using Apple's included Mac OS X tool called PlistBuddy located in /usr/libexec/PlistBuddy. (see http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/PlistBuddy.8.html)

As part of a post build step you could run a command like the following to set the minimum OS X version to 10.6.6. (This is only a sample to show you how it can be done.)

dim dbg as String
if debugBuild then dbg = ".debug"
dim appNameForShell as string
appNameForShell = PropertyValue("App.MacOSXAppName")+ dbg +".app" + "/Contents/Info.plist"
// there are several other special characters that you might need to escape
appNameForShell = replaceall(appNameForShell, " ", "\ ")
dim s as string
s = DoShellCommand("/usr/libexec/PlistBuddy -c ""Set :LSMinimumSystemVersion \""10.6.6\"" "" " + CurrentBuildLocation + "/" + appNameForShell )
print s

This saves you having to do this change in the Property List Editor manually every time.

Making it easier to adjust the plist is frequently requested but in the meantime you can use either of these mechanisms to update the property list generated by Real Studio.

Tuesday, March 8, 2011

Real Studio 2011 Release 1 is now available

Real Studio 2011 Release 1 is now shipping.  Adding 35 new features and 114 improvements, this release features easier deployment of web applications, improved HTMLViewer support and major advancements in Cocoa support.

* Web application deployment with Real Studio is now just as easy as creating the app itself!  We are now offering a new CGI build option that outputs a Perl script.  This script is placed in the cgi-bin folder, allowing for easier web deployment and more hosting service options. 

* RealSQLDatabase now has a new MultiUser property that lets web applications allow multiple users to access a RealSQLDatabase file at the same time. This may eliminate the need for some web applications to require a database server.

* A new, native Microsoft SQL Server plugin has been added. This plugin supports Windows only.

* This release includes a huge number of improvements to Real Studio’s Cocoa framework.

* Improved HTMLViewer support offers the options to get/set custom user agent strings and increase/decrease the font size.

* The WebListBox now has a CellClick event (just like the desktop Listbox). It also now has Cell and Column Style properties allowing or greater control over the look and behavior of cells.
The new DragPicture property lets you use an image for dragging.

Real Studio 2011 Release 1 is now available for download at, our Downloads page.  For full details about what’s in this release view the product Release Notes.

Issue for Web Edition Projects Going From 2011 R1 back to 2010 R5

If you are creating web applications and are going back and forth between Real Studio 2010 R5 (or R5.1) and 2011 R1, there is the potential for project corruption but there is also a solution.

If you save a project in 2011 R1 then reopen it in 2010 R5, the project will open but it will not run. When you run the project, you will get a fatal error:
Just as Real Studio warns when you opened the project, there is the potential for data loss. In this case, the likelihood is very high. In R1 there is now a TargetWeb constant which you can use to write code in classes and modules you share between your web and desktop projects. This constant can be used to include code in shared classes and modules that should only be compiled into your web projects. Unfortunately in order to support this, the project format is no longer backwards compatible. Again, this is only for web projects. Desktop and console projects are not affected. Once you save a project in R1 it will no longer run in R5.

The good news is that there's a relatively easy way to fix your project should this happen. To fix your project:

1. Using R1, save your project in XML format by choosing Save As from the File menu and then choosing the XML Project option from the Format popup menu.

2. Quit Real Studio and open the XML version of the project in a text editor.

3. Search for 3 and then change the 3 to a 1.

4. Search for True and delete this line.

5. Search for -1 and change the -1 to 9000.

6. Save your project. Now you can reopen it in 2010 R5 and it will run. You will still get the warning when you open it but this will go away once you save the project in R5.

If you are using the Version Control Format for your project, do the following:

1. Open your project in a text editor.

2. Change Type=Web to Type=Console.

3. Change WebLivePort=-1 to WebLivePort=9000.

4. Save your project. It will now open and run in 2010 R5.

Again this particular issue only affects web projects that were saved in R1 and need to be opened and run in R5.

We apologize for this inconvenience. We really try to keep the project format as compatible as possible when you move back and forth between versions but that's not always possible. However, we are going to add something in a future release of Real Studio so that you don't accidentally find yourself in situations like this one.

Wednesday, March 2, 2011

Detecting Modifier Keys

Sometimes it is necessary, or at least user-friendly, to adjust your interface when the user holds down modifier keys. For example, iTunes changes its "Create Playlist" button from a plus icon to a gear icon when the option key is held down. The goal is to inform the user that option-clicking the button will perform a different task.



At first glance you might think that simply looking for the option key in a KeyDown event will do the trick. The problem is KeyDown/KeyUp does not fire for modifier keys. The solution is to use a Timer, which I'll show you how to setup. In this tutorial we'll be creating a timer to detect the option/alt key, though this class could be adapted to read any of the modifiers.

First of all, we need to decide whether to create a timer embedded on a Window, or to create a subclass. Either technique will work, but the subclass creates reusable code which I always recommend. Also, the subclass will allow us to trigger events which will come in handy.

Start by creating a new class called "OptionTimer" whose super is "Timer". Next, add a property "Pressed As Boolean", an event "KeyDown", and a second event "KeyUp" to OptionTimer. In the Action event insert the following code:

If Keyboard.AsyncAltKey = True And Pressed = False Then
Pressed = True
RaiseEvent KeyDown
Else If KeyBoard.AsyncAltKey = False And Pressed = True Then
Pressed = False
RaiseEvent KeyUp
End If

That's it, nothing more the class needs to do. So go to your Window and place a Timer on it. Set the super to "OptionTimer" and now you can insert code into the events for that timer. You'll also want to adjust the period of the timer to something small such as 250 to make sure the events are responsive.

To test it we could use a MsgBox in each event but MsgBoxes are blocking and require user interaction. Since this test is about user interaction, we should avoid the MsgBox. So instead, in the KeyDown event insert a single "Beep" command. And in the KeyUp event insert two "Beep" commands. When you run your project, you should hear a beep when you press the option key and two beeps when you release it.