Thursday, June 16, 2005

Maximum CFC method length

I just bumped into size limit of a method in a cfc. Since the methods get turned into java classes, they are limited in size to 65535 characters. Before you get all nuts telling me "DOOD! Your methods shouldn't be that big", relax. It was just a bunch of database calls that happen sequentially. There's no real complexity in there, only tedium.

Lucky for me, it's pretty easy to break it up into a bunch of small private methods. Just for reference, you'll hit the limit somewhere around 900 lines of fairly dense code. If things start looking that big, it's time to start rethinking the structure.

2 comments:

  1. What sort of error message did you get when you hit the limit? Also, to clarify, you are saying that the methods/functions get turned into classes and those have the limit, not the component itself that gets turned into a class that incurs the limit? I figured the entire component would have been turned into the class...

    ReplyDelete
  2. The actual error message is a reference to the class that generated the message followed by "Code of a method longer than 65535 bytes"

    That's right, each method of the cfc gets turned into a .class file unlike regluar .cfm files which get one class per file. Take a look inside your cfinstaldirectory\wwwroot\WEB-INF\cfclasses
    directory and you can see the class files.

    It's my understanding that the class files are what have the size limitation directly. I'm not sure if a plain .cfm page has the same limitation or if there is some mechanism that cf uses to break the classes into pieces.

    ReplyDelete