Financially troubled Colonial Williamsburg, plaqued in recent years by rising costs and poor attendance, has received a $4 million gift from the Rockefeller Brothers Fund, officials of the restored Virginia capital announced yesterday.

The grant, which will be used primarily for major restoration projects, underscores Colonial Williamsburg's continuing dependence on the charities of the Rockefeller family, whose gifts created the restoration 52 years ago.

Carlisle H. Humelsine, chairman of Colonial Williamsburg trustees, said the gift will "add to the long-term financial security" of Williamsburg, a major Virginia tourist attraction.

In 1976, Colonial Williamsburg launched a campaign to broaden its support by creating a development division that has generated $8.6 million in gifts from 2,000 corporations and individuals.

Of that total, $1 million came from another Rockefeller fund, the Winthrop Rockefeller Charitable Trust. More than half og the remaining amount, $4 million, came in a single gift from DeWitt Wallace of Reader's Digest.

The Wallace gift is being used to modernize the Colonial Williamsburg Information Center, the starting point for most tourists' visits to the restored Virginia capital.

The Rockefeller Brothers gift will be used to revise and refurnish the Governor's Palace, the old capital's most elegant building, and to reconstruct one 18th century home and the outbuildings of two others. The money also will be used to create additional 18th century merchandise shops on Duke of Gloucester Street, which was the center of business activity in Colonial Williamsburg.

Humeline warned that the Rockefeller gift "cannot be considered available to mee the increasingly difficult problem of rising costs . . . We must do this through our development program and the internal measures we are presently carrying forwars," he said.

The "internal measures" include staff reductions and price increases that Colonial Williamsburg began in 1976 as soon as it became apparent that visitor totals in that bicentennial year would fall far short of expectations.

The foundation had invested heavily to accommodate a hoped for surge of bicentennial visitors, but the number of tourists that yeat totaled only 1.29 million, barely more than in 1975. The visitor total fell to 1.1 million in 1977 and appears headed for that level this year, a foundation spokesman said.

By raising some prices, the foundation has managed in most years to meet operating expenses with revenue from ticket sales, hotels, restaurants and gift shops, the spokesman said. But the foundation has not made enough money to contribute to future development.